From 40e3157a523f145bc7ed56f86a9f6afe332add0f Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 2 Apr 2024 07:52:44 -0700 Subject: [PATCH 1/2] Fix `flow version` output --- internal/version/version.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index a60fec245..c7b09fe22 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -21,7 +21,6 @@ package version import ( "encoding/json" "fmt" - "log" "runtime/debug" "strings" @@ -45,12 +44,12 @@ func (c versionCmd) Print(format string) error { txtBuilder.WriteString(fmt.Sprintf("Version: %s\n", c.Version)) txtBuilder.WriteString(fmt.Sprintf("Commit: %s\n", c.Commit)) - txtBuilder.WriteString(fmt.Sprintf("\nFlow Package Dependencies \n")) + txtBuilder.WriteString("\nFlow Package Dependencies \n") for _, dep := range c.Dependencies { txtBuilder.WriteString(fmt.Sprintf("%s %s\n", dep.Path, dep.Version)) } - log.Println(txtBuilder.String()) + fmt.Println(txtBuilder.String()) return nil @@ -60,7 +59,7 @@ func (c versionCmd) Print(format string) error { return err } - log.Println(string(jsonRes)) + fmt.Println(string(jsonRes)) return nil @@ -99,7 +98,7 @@ func (c *versionCmd) MarshalJSON() ([]byte, error) { var Cmd = &cobra.Command{ Use: "version", Short: "View version and commit information", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { semver := build.Semver() commit := build.Commit() @@ -110,8 +109,7 @@ var Cmd = &cobra.Command{ bi, ok := debug.ReadBuildInfo() if !ok { - log.Printf("Failed to read build info") - return + return fmt.Errorf("failed to read build info") } // only add dependencies from github.com/onflow @@ -122,8 +120,9 @@ var Cmd = &cobra.Command{ } if err := v.Print(command.Flags.Format); err != nil { - log.Printf("Failed to print version information: %s", err) - return + return err } + + return nil }, } From 9fd04e6417615fe7d74ab3fe0c6d781d35bf0ded Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 2 Apr 2024 10:17:32 -0700 Subject: [PATCH 2/2] silence usage/errors --- cmd/flow/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/flow/main.go b/cmd/flow/main.go index 15af895c4..63ac4f8d3 100644 --- a/cmd/flow/main.go +++ b/cmd/flow/main.go @@ -153,6 +153,11 @@ func main() { cmd.SetUsageTemplate(command.UsageTemplate) + // Don't print usage on error + cmd.SilenceUsage = true + // Don't print errors on error (we handle them) + cmd.SilenceErrors = true + if err := cmd.Execute(); err != nil { util.Exit(1, err.Error()) }