feat: add flag force-indirect

main
sudo pacman -Syu 2024-06-06 01:13:22 +07:00
parent 076fe2056d
commit 964ace5a01
3 changed files with 16 additions and 7 deletions

View File

@ -14,10 +14,11 @@ const (
type action struct { type action struct {
ghClient *github.Client ghClient *github.Client
flags struct { flags struct {
depsFile string depsFile string
depsURL string depsURL string
verbose bool verbose bool
dryRun bool dryRun bool
forceIndirect bool
} }
} }
@ -36,6 +37,7 @@ func (a *action) getFlags(c *cli.Context) {
a.flags.depsURL = c.String(flagDepsURLName) a.flags.depsURL = c.String(flagDepsURLName)
a.flags.dryRun = c.Bool(flagDryRun) a.flags.dryRun = c.Bool(flagDryRun)
a.flags.forceIndirect = c.Bool(flagForceIndirectName)
a.log("Flags %+v\n", a.flags) a.log("Flags %+v\n", a.flags)
} }

View File

@ -56,7 +56,7 @@ func (a *action) Run(c *cli.Context) error {
existVendor = true existVendor = true
} }
depsStr, useDepFile, err := a.runReadDepsFile(c) depsStr, useDepFile, err := a.runReadDepsFile()
if err != nil { if err != nil {
return err return err
} }
@ -119,7 +119,7 @@ func (a *action) runGetImportedModules(c *cli.Context) (map[string]Module, error
} }
// Ignore indirect module // Ignore indirect module
if importedModule.Indirect { if importedModule.Indirect && !a.flags.forceIndirect {
continue continue
} }
@ -136,7 +136,7 @@ func (a *action) runGetImportedModules(c *cli.Context) (map[string]Module, error
return mapImportedModules, nil return mapImportedModules, nil
} }
func (a *action) runReadDepsFile(c *cli.Context) (depsStr string, useDepFile bool, err error) { func (a *action) runReadDepsFile() (depsStr string, useDepFile bool, err error) {
// Try to read from url first // Try to read from url first
if a.flags.depsURL != "" { if a.flags.depsURL != "" {
depsURL, err := url.Parse(a.flags.depsURL) depsURL, err := url.Parse(a.flags.depsURL)

View File

@ -30,6 +30,9 @@ const (
flagDryRun = "dry-run" flagDryRun = "dry-run"
flagDryRunName = "demo what would be done" flagDryRunName = "demo what would be done"
flagForceIndirectName = "force-indirect"
flagForceIndirectUsage = "force update indirect module"
) )
var aliasFlagVerbose = []string{"v"} var aliasFlagVerbose = []string{"v"}
@ -70,6 +73,10 @@ func NewApp(
Name: flagDryRun, Name: flagDryRun,
Usage: flagDryRunName, Usage: flagDryRunName,
}, },
&cli.BoolFlag{
Name: flagForceIndirectName,
Usage: flagForceIndirectUsage,
},
}, },
Action: a.Run, Action: a.Run,
}, },