diff --git a/cmd/uplinkng/cmd_version.go b/cmd/uplinkng/cmd_version.go index 72715a906..215a72562 100644 --- a/cmd/uplinkng/cmd_version.go +++ b/cmd/uplinkng/cmd_version.go @@ -4,12 +4,16 @@ package main import ( + "fmt" "runtime/debug" "strconv" "strings" + "time" "github.com/zeebo/clingy" "github.com/zeebo/errs" + + "storj.io/private/version" ) type cmdVersion struct { @@ -28,6 +32,28 @@ func (c *cmdVersion) Setup(params clingy.Parameters) { } func (c *cmdVersion) Execute(ctx clingy.Context) error { + if version.Build.Release { + fmt.Fprintln(ctx, "Release build") + } else { + fmt.Fprintln(ctx, "Development build") + } + + { + tw := newTabbedWriter(ctx.Stdout()) + if !version.Build.Version.IsZero() { + tw.WriteLine("Version:", version.Build.Version.String()) + } + if !version.Build.Timestamp.IsZero() { + tw.WriteLine("Build timestamp:", version.Build.Timestamp.Format(time.RFC822)) + } + if version.Build.CommitHash != "" { + tw.WriteLine("Git commit:", version.Build.CommitHash) + } + tw.Done() + } + + fmt.Fprintln(ctx) + bi, ok := debug.ReadBuildInfo() if !ok { return errs.New("unable to read build info") diff --git a/cmd/uplinkng/tabbed_writer.go b/cmd/uplinkng/tabbed_writer.go index 8ad971623..f36d47738 100644 --- a/cmd/uplinkng/tabbed_writer.go +++ b/cmd/uplinkng/tabbed_writer.go @@ -31,7 +31,9 @@ func (t *tabbedWriter) Done() { func (t *tabbedWriter) WriteLine(parts ...interface{}) { if !t.wrote { - fmt.Fprintln(t.tw, strings.Join(t.headers, "\t")) + if len(t.headers) > 0 { + fmt.Fprintln(t.tw, strings.Join(t.headers, "\t")) + } t.wrote = true } for i, part := range parts {