Skip to content

Commit

Permalink
Fix flow version output bug (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Apr 2, 2024
1 parent 3a0b0d5 commit 783914c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
17 changes: 8 additions & 9 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package version
import (
"encoding/json"
"fmt"
"log"
"runtime/debug"
"strings"

Expand All @@ -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

Expand All @@ -60,7 +59,7 @@ func (c versionCmd) Print(format string) error {
return err
}

log.Println(string(jsonRes))
fmt.Println(string(jsonRes))

return nil

Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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
},
}

0 comments on commit 783914c

Please sign in to comment.