diff --git a/README.md b/README.md index 220eb1f..2c8e58e 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ GoBump is a simple command-line tool written in Go that allows you to update the ## Usage ```shell -gobump --packages=,... --modroot= +gobump --packages= ... --modroot= ``` ### Flags -* `--packages`: A comma-separated list of packages to update. Each package should be in the format `package@version`. +* `--packages`: A space-separated list of packages to update. Each package should be in the format `package@version`. * `--modroot`: Path to the go.mod root. If not specified, it defaults to the current directory. -* `--replaces`: A comma-separated list of packages to replace. Each entry should be in the format `old=new@version`. +* `--replaces`: A space-separated list of packages to replace. Each entry should be in the format `old=new@version`. * `--go-version`: set the go-version for 'go mod tidy' command. * `--show-diff`: Show the difference between the original and 'go.mod' files. * `--tidy`: Run 'go mod tidy' command. @@ -19,7 +19,7 @@ gobump --packages=,... --modroot= ## Example ```shell -gobump --packages=github.com/pkg/errors@v0.9.1,golang.org/x/mod@v0.4.2 --modroot=/path/to/your/project +gobump --packages="github.com/pkg/errors@v0.9.1 golang.org/x/mod@v0.4.2" --modroot=/path/to/your/project ``` This will update the versions of `github.com/pkg/errors` and `golang.org/x/mod` in your `go.mod` file. diff --git a/cmd/gobump/root.go b/cmd/gobump/root.go index d841670..3619cd6 100644 --- a/cmd/gobump/root.go +++ b/cmd/gobump/root.go @@ -2,8 +2,6 @@ package cmd import ( "fmt" - "log" - "os" "strings" "github.com/chainguard-dev/gobump/pkg/types" @@ -30,18 +28,16 @@ var rootCmd = &cobra.Command{ Args: cobra.NoArgs, // Uncomment the following line if your bare application // has an action associated with it: - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { if rootFlags.packages == "" { - log.Println("Usage: gobump -packages=,...") - os.Exit(1) + return fmt.Errorf("Error: No packages provided. Usage: gobump --packages=\" ...\"") } packages := strings.Split(rootFlags.packages, " ") pkgVersions := map[string]*types.Package{} for _, pkg := range packages { parts := strings.Split(pkg, "@") if len(parts) != 2 { - fmt.Println("Usage: gobump -packages=,...") - os.Exit(1) + return fmt.Errorf("Error: Invalid package format. Each package should be in the format . Usage: gobump --packages=\" ...\"") } pkgVersions[parts[0]] = &types.Package{ Name: parts[0], @@ -55,14 +51,12 @@ var rootCmd = &cobra.Command{ for _, replace := range replaces { parts := strings.Split(replace, "=") if len(parts) != 2 { - fmt.Println("Usage: gobump -replaces=,...") - os.Exit(1) + return fmt.Errorf("Error: Invalid replace format. Each replace should be in the format . Usage: gobump -replaces=\" ...\"") } // extract the new package name and version rep := strings.Split(strings.TrimPrefix(replace, fmt.Sprintf("%s=", parts[0])), "@") if len(rep) != 2 { - fmt.Println("Usage: gobump -replaces=,...") - os.Exit(1) + return fmt.Errorf("Error: Invalid replace format. Each replace should be in the format . Usage: gobump -replaces=\" ...\"") } // Merge/Add the packages to replace reusing the initial list of packages pkgVersions[rep[0]] = &types.Package{ @@ -75,9 +69,9 @@ var rootCmd = &cobra.Command{ } if _, err := update.DoUpdate(pkgVersions, &types.Config{Modroot: rootFlags.modroot, Tidy: rootFlags.tidy, GoVersion: rootFlags.goVersion, ShowDiff: rootFlags.showDiff}); err != nil { - fmt.Println("failed running update: ", err) - os.Exit(1) + return fmt.Errorf("Failed to running update. Error: %v", err) } + return nil }, }