-
Notifications
You must be signed in to change notification settings - Fork 402
/
cmd_version.go
75 lines (61 loc) · 1.55 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"runtime/debug"
"strconv"
"strings"
"time"
"github.com/zeebo/clingy"
"github.com/zeebo/errs"
"storj.io/private/version"
)
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), clingy.Boolean,
).(bool)
}
func (c *cmdVersion) Execute(ctx context.Context) error {
if version.Build.Release {
fmt.Fprintln(clingy.Stdout(ctx), "Release build")
} else {
fmt.Fprintln(clingy.Stdout(ctx), "Development build")
}
{
tw := newTabbedWriter(clingy.Stdout(ctx))
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(clingy.Stdout(ctx))
bi, ok := debug.ReadBuildInfo()
if !ok {
return errs.New("unable to read build info")
}
tw := newTabbedWriter(clingy.Stdout(ctx), "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
}