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 .PHONY: all test-color lint
all: test-color lint all: test-color lint
go mod tidy
test-color: test-color:
go install github.com/haunt98/go-test-color@latest go install github.com/haunt98/go-test-color@latest

View File

@ -6,6 +6,10 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
const (
defaultDepsFile = ".deps"
)
type action struct { type action struct {
flags struct { flags struct {
depsFile string depsFile string
@ -20,12 +24,18 @@ func (a *action) RunHelp(c *cli.Context) error {
} }
func (a *action) getFlags(c *cli.Context) { func (a *action) getFlags(c *cli.Context) {
a.flags.verbose = c.Bool(flagVerbose) a.flags.verbose = c.Bool(flagVerboseName)
a.flags.depsFile = c.String(flagDepsFile)
a.flags.depsURL = c.String(flagDepsURL) 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.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{}) { 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 { if err := json.Unmarshal([]byte(goOutputStr), &importedModules); err != nil {
return nil, fmt.Errorf("failed to json unmarshal: %w", err) 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{}) mapImportedModules := make(map[string]struct{})
for _, importedModule := range importedModules { for _, importedModule := range importedModules {
mapImportedModules[importedModule.Path] = struct{}{} mapImportedModules[importedModule.Path] = struct{}{}
} }
a.log("imported modules: %+v\n", importedModules) a.log("Imported modules: %+v\n", importedModules)
return mapImportedModules, nil return mapImportedModules, nil
} }
@ -157,7 +157,7 @@ func (a *action) runUpgradeModule(
if modulePath == "" { if modulePath == "" {
return successUpgradedModules, nil return successUpgradedModules, nil
} }
a.log("line: %s", modulePath) a.log("Line: %s", modulePath)
// Check if modulePath is imported module, otherwise skip // Check if modulePath is imported module, otherwise skip
if _, ok := mapImportedModules[modulePath]; !ok { if _, ok := mapImportedModules[modulePath]; !ok {
@ -171,13 +171,13 @@ func (a *action) runUpgradeModule(
if err != nil { if err != nil {
return successUpgradedModules, fmt.Errorf("failed to run go %+v: %w", strings.Join(goListArgs, " "), err) 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{} module := Module{}
if err := json.Unmarshal(goOutput, &module); err != nil { if err := json.Unmarshal(goOutput, &module); err != nil {
return successUpgradedModules, fmt.Errorf("failed to json unmarshal: %w", err) return successUpgradedModules, fmt.Errorf("failed to json unmarshal: %w", err)
} }
a.log("module: %+v", module) a.log("Module: %+v", module)
if module.Update == nil { if module.Update == nil {
color.PrintAppOK(name, fmt.Sprintf("You already have latest [%s] version [%s]", module.Path, module.Version)) 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 { if err != nil {
return successUpgradedModules, fmt.Errorf("failed to run go %+v: %w", strings.Join(goGetArgs, " "), err) 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) successUpgradedModules = append(successUpgradedModules, module)
@ -215,7 +215,7 @@ func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to run go %+v: %w", strings.Join(goModArgs, " "), err) 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 { if existVendor {
// go mod vendor // go mod vendor
@ -224,7 +224,7 @@ func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to run go %+v: %w", strings.Join(goModArgs, " "), err) 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 return nil
@ -258,7 +258,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []Module, e
if err != nil { if err != nil {
return fmt.Errorf("failed to run git %+v: %w", strings.Join(gitAddArgs, " "), err) 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 // git commit
gitCommitMessage := "build: upgrade modules\n" gitCommitMessage := "build: upgrade modules\n"
@ -270,7 +270,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []Module, e
if err != nil { if err != nil {
return fmt.Errorf("failed to run git %+v: %w", strings.Join(gitCommitArgs, " "), err) 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 return nil
} }

View File

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