fix: remove default value of deps file

main
sudo pacman -Syu 2022-08-16 10:34:55 +07:00
parent e49cf9eb9e
commit e2ec575af0
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
4 changed files with 45 additions and 35 deletions

View File

@ -1,6 +1,7 @@
.PHONY: all test-color lint
all: test-color lint
go mod tidy
test-color:
go install github.com/haunt98/go-test-color@latest

View File

@ -6,6 +6,10 @@ import (
"github.com/urfave/cli/v2"
)
const (
defaultDepsFile = ".deps"
)
type action struct {
flags struct {
depsFile string
@ -20,12 +24,18 @@ func (a *action) RunHelp(c *cli.Context) error {
}
func (a *action) getFlags(c *cli.Context) {
a.flags.verbose = c.Bool(flagVerbose)
a.flags.depsFile = c.String(flagDepsFile)
a.flags.depsURL = c.String(flagDepsURL)
a.flags.verbose = c.Bool(flagVerboseName)
a.flags.depsFile = c.String(flagDepsFileName)
if a.flags.depsFile == "" {
a.log("Fallback to default deps file [%s]\n", defaultDepsFile)
a.flags.depsFile = defaultDepsFile
}
a.flags.depsURL = c.String(flagDepsURLName)
a.flags.dryRun = c.Bool(flagDryRun)
a.log("flags %+v", a.flags)
a.log("Flags %+v", a.flags)
}
func (a *action) log(format string, v ...interface{}) {

View File

@ -96,13 +96,13 @@ func (a *action) runGetImportedModules(c *cli.Context) (map[string]struct{}, err
if err := json.Unmarshal([]byte(goOutputStr), &importedModules); err != nil {
return nil, fmt.Errorf("failed to json unmarshal: %w", err)
}
a.log("go output: %s", string(goOutput))
a.log("Go output: %s", string(goOutput))
mapImportedModules := make(map[string]struct{})
for _, importedModule := range importedModules {
mapImportedModules[importedModule.Path] = struct{}{}
}
a.log("imported modules: %+v\n", importedModules)
a.log("Imported modules: %+v\n", importedModules)
return mapImportedModules, nil
}
@ -157,7 +157,7 @@ func (a *action) runUpgradeModule(
if modulePath == "" {
return successUpgradedModules, nil
}
a.log("line: %s", modulePath)
a.log("Line: %s", modulePath)
// Check if modulePath is imported module, otherwise skip
if _, ok := mapImportedModules[modulePath]; !ok {
@ -171,13 +171,13 @@ func (a *action) runUpgradeModule(
if err != nil {
return successUpgradedModules, fmt.Errorf("failed to run go %+v: %w", strings.Join(goListArgs, " "), err)
}
a.log("go output: %s", string(goOutput))
a.log("Go output: %s", string(goOutput))
module := Module{}
if err := json.Unmarshal(goOutput, &module); err != nil {
return successUpgradedModules, fmt.Errorf("failed to json unmarshal: %w", err)
}
a.log("module: %+v", module)
a.log("Module: %+v", module)
if module.Update == nil {
color.PrintAppOK(name, fmt.Sprintf("You already have latest [%s] version [%s]", module.Path, module.Version))
@ -195,7 +195,7 @@ func (a *action) runUpgradeModule(
if err != nil {
return successUpgradedModules, fmt.Errorf("failed to run go %+v: %w", strings.Join(goGetArgs, " "), err)
}
a.log("go output: %s", string(goOutput))
a.log("Go output: %s", string(goOutput))
successUpgradedModules = append(successUpgradedModules, module)
@ -215,7 +215,7 @@ func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
if err != nil {
return fmt.Errorf("failed to run go %+v: %w", strings.Join(goModArgs, " "), err)
}
a.log("go output: %s", string(goOutput))
a.log("Go output: %s", string(goOutput))
if existVendor {
// go mod vendor
@ -224,7 +224,7 @@ func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
if err != nil {
return fmt.Errorf("failed to run go %+v: %w", strings.Join(goModArgs, " "), err)
}
a.log("go output: %s", string(goOutput))
a.log("Go output: %s", string(goOutput))
}
return nil
@ -258,7 +258,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []Module, e
if err != nil {
return fmt.Errorf("failed to run git %+v: %w", strings.Join(gitAddArgs, " "), err)
}
a.log("git output: %s", string(gitOutput))
a.log("Git output: %s", string(gitOutput))
// git commit
gitCommitMessage := "build: upgrade modules\n"
@ -270,7 +270,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []Module, e
if err != nil {
return fmt.Errorf("failed to run git %+v: %w", strings.Join(gitCommitArgs, " "), err)
}
a.log("git output: %s", string(gitOutput))
a.log("Git output: %s", string(gitOutput))
return nil
}

View File

@ -11,20 +11,20 @@ const (
name = "update-go-mod"
usage = "excatly like the name says"
flagVerbose = "verbose"
flagDepsFile = "deps-file"
flagDepsURL = "deps-url"
flagDryRun = "dry-run"
commandRunName = "run"
commandRunUsage = "run the program"
commandRun = "run"
flagVerboseName = "verbose"
flagVerboseUsage = "show what is going on"
usageCommandRun = "run the program"
usageFlagVerbose = "show what is going on"
usageDepsFile = "file which show what deps need to upgrade"
usageDepsURL = "url which show what deps need to upgrade"
usageDryRun = "demo what would be done"
flagDepsFileName = "deps-file"
flagDepsFileUsage = "file which show what deps need to upgrade"
defaultDepsFile = ".deps"
flagDepsURLName = "deps-url"
flagDepsURLUsage = "url which show what deps need to upgrade"
flagDryRun = "dry-run"
flagDryRunName = "demo what would be done"
)
var aliasFlagVerbose = []string{"v"}
@ -41,26 +41,25 @@ func NewApp() *App {
Usage: usage,
Commands: []*cli.Command{
{
Name: commandRun,
Usage: usageCommandRun,
Name: commandRunName,
Usage: commandRunUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: flagVerbose,
Name: flagVerboseName,
Aliases: aliasFlagVerbose,
Usage: usageFlagVerbose,
Usage: flagVerboseUsage,
},
&cli.StringFlag{
Name: flagDepsFile,
Usage: usageDepsFile,
Value: defaultDepsFile,
Name: flagDepsFileName,
Usage: flagDepsFileUsage,
},
&cli.StringFlag{
Name: flagDepsURL,
Usage: usageDepsURL,
Name: flagDepsURLName,
Usage: flagDepsURLUsage,
},
&cli.BoolFlag{
Name: flagDryRun,
Usage: usageDryRun,
Usage: flagDryRunName,
},
},
Action: a.Run,