-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.go
61 lines (51 loc) · 987 Bytes
/
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
package version
import (
"fmt"
"runtime"
"github.com/urfave/cli"
"jrubin.io/zb/cmd"
)
// Cmd is the version command
var Cmd cmd.Constructor = &cc{}
type cc struct {
Short bool
}
func (co *cc) New(app *cli.App) cli.Command {
return cli.Command{
Name: "version",
Usage: fmt.Sprintf("prints the version of %s", app.Name),
Action: co.run,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "short, s",
Destination: &co.Short,
},
},
}
}
func (co *cc) run(c *cli.Context) error {
if co.Short {
fmt.Fprintf(c.App.Writer, "%s\n", c.App.Version)
return nil
}
ctx := cmd.Context(c)
var commit string
if ctx.GitCommit != nil {
commit = *ctx.GitCommit
if len(commit) >= 7 {
commit = commit[:7]
}
}
var buildDate string
if ctx.BuildDate != nil {
buildDate = *ctx.BuildDate
}
fmt.Fprintf(c.App.Writer, "%s version %s (git: %s, date: %s, %s)\n",
c.App.Name,
c.App.Version,
commit,
buildDate,
runtime.Version(),
)
return nil
}