2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
)
|
|
|
|
|
|
|
|
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'),
|
|
|
|
clingy.Transform(strconv.ParseBool)).(bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdVersion) Execute(ctx clingy.Context) error {
|
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
|
|
if !ok {
|
|
|
|
return errs.New("unable to read build info")
|
|
|
|
}
|
|
|
|
|
2021-04-06 04:40:04 +01:00
|
|
|
tw := newTabbedWriter(ctx.Stdout(), "PATH", "VERSION")
|
|
|
|
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
|
|
|
|
}
|