diff --git a/command/version.go b/command/version.go index 0691961b..fd35b8c2 100644 --- a/command/version.go +++ b/command/version.go @@ -1,7 +1,6 @@ package command import ( - "bytes" "fmt" "github.com/jrasell/levant/buildtime" @@ -10,7 +9,6 @@ import ( // VersionCommand is a Command implementation that prints the version. type VersionCommand struct { - Revision string Version string VersionPrerelease string UI cli.Ui @@ -28,18 +26,14 @@ func (c *VersionCommand) Synopsis() string { // Run executes the version command. func (c *VersionCommand) Run(_ []string) int { - var versionString bytes.Buffer - fmt.Fprintf(&versionString, "Levant v%s", c.Version) - if c.VersionPrerelease != "" { - fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease) + v := fmt.Sprintf("Levant v%s", c.Version) - if c.Revision != "" { - fmt.Fprintf(&versionString, " (%s)", c.Revision) - } + if c.VersionPrerelease != "" { + v = v + fmt.Sprintf("-%s", c.VersionPrerelease) } - c.UI.Output(versionString.String()) + c.UI.Output(v) c.UI.Output(fmt.Sprintf("Date: %s", buildtime.BuildDate)) c.UI.Output(fmt.Sprintf("Commit: %s", buildtime.GitCommit)) c.UI.Output(fmt.Sprintf("Branch: %s", buildtime.GitBranch)) diff --git a/main.go b/main.go index e26f0535..cf49156c 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,14 @@ func RunCustom(args []string, commands map[string]cli.CommandFactory) int { exitCode, err := cli.Run() if err != nil { - fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error()) + _, pErr := fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error()) + + // If we are unable to log to stderr; try just printing the error to + // provide some insight. + if pErr != nil { + fmt.Print(pErr) + } + return 1 }