2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-30 10:51:31 +01:00
|
|
|
"context"
|
2021-10-21 15:19:10 +01:00
|
|
|
"fmt"
|
2021-03-31 16:56:34 +01:00
|
|
|
"runtime/debug"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2021-10-21 15:19:10 +01:00
|
|
|
"time"
|
2021-03-31 16:56:34 +01:00
|
|
|
|
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
"github.com/zeebo/errs"
|
2021-10-21 15:19:10 +01:00
|
|
|
|
|
|
|
"storj.io/private/version"
|
2021-03-31 16:56:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdVersion struct {
|
|
|
|
verbose bool
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func newCmdVersion() *cmdVersion {
|
|
|
|
return &cmdVersion{}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
func (c *cmdVersion) Setup(params clingy.Parameters) {
|
|
|
|
c.verbose = params.Flag(
|
2021-03-31 16:56:34 +01:00
|
|
|
"verbose", "prints all dependency versions", false,
|
|
|
|
clingy.Short('v'),
|
2021-12-09 19:21:52 +00:00
|
|
|
clingy.Transform(strconv.ParseBool), clingy.Boolean,
|
|
|
|
).(bool)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdVersion) Execute(ctx context.Context) error {
|
2021-10-21 15:19:10 +01:00
|
|
|
if version.Build.Release {
|
2022-08-30 10:51:31 +01:00
|
|
|
fmt.Fprintln(clingy.Stdout(ctx), "Release build")
|
2021-10-21 15:19:10 +01:00
|
|
|
} else {
|
2022-08-30 10:51:31 +01:00
|
|
|
fmt.Fprintln(clingy.Stdout(ctx), "Development build")
|
2021-10-21 15:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2022-08-30 10:51:31 +01:00
|
|
|
tw := newTabbedWriter(clingy.Stdout(ctx))
|
2021-10-21 15:19:10 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
fmt.Fprintln(clingy.Stdout(ctx))
|
2021-10-21 15:19:10 +01:00
|
|
|
|
2021-03-31 16:56:34 +01:00
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
|
|
if !ok {
|
|
|
|
return errs.New("unable to read build info")
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
tw := newTabbedWriter(clingy.Stdout(ctx), "PATH", "VERSION")
|
2021-04-06 04:40:04 +01:00
|
|
|
defer tw.Done()
|
2021-03-31 16:56:34 +01:00
|
|
|
|
2021-04-06 04:40:04 +01:00
|
|
|
tw.WriteLine(bi.Main.Path, bi.Main.Version)
|
2021-03-31 16:56:34 +01:00
|
|
|
for _, mod := range bi.Deps {
|
|
|
|
if c.verbose || strings.HasPrefix(mod.Path, "storj.io/") {
|
2021-04-06 04:40:04 +01:00
|
|
|
tw.WriteLine(mod.Path, mod.Version)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|