-
Notifications
You must be signed in to change notification settings - Fork 402
/
cmd_version.go
47 lines (37 loc) · 928 Bytes
/
cmd_version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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
}
func newCmdVersion() *cmdVersion {
return &cmdVersion{}
}
func (c *cmdVersion) Setup(params clingy.Parameters) {
c.verbose = params.Flag(
"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")
}
tw := newTabbedWriter(ctx.Stdout(), "PATH", "VERSION")
defer tw.Done()
tw.WriteLine(bi.Main.Path, bi.Main.Version)
for _, mod := range bi.Deps {
if c.verbose || strings.HasPrefix(mod.Path, "storj.io/") {
tw.WriteLine(mod.Path, mod.Version)
}
}
return nil
}