-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
cmd_version.go
62 lines (52 loc) · 1 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
//
// Show our version.
//
package main
import (
"context"
"flag"
"fmt"
"runtime"
"github.com/google/subcommands"
)
//
// This is set via the travis-builder (or will be when I set that up).
//
var (
version = "unreleased"
)
type versionCmd struct {
verbose bool
}
//
// Glue
//
func (*versionCmd) Name() string { return "version" }
func (*versionCmd) Synopsis() string { return "Show our version." }
func (*versionCmd) Usage() string {
return `version :
Report upon our version, and exit.
`
}
//
// Flag setup
//
func (p *versionCmd) SetFlags(f *flag.FlagSet) {
f.BoolVar(&p.verbose, "verbose", false, "Show go version the binary was generated with.")
}
//
// Show our version.
//
func showVersion(verbose bool) {
fmt.Printf("%s\n", version)
if verbose {
fmt.Printf("Built with %s\n", runtime.Version())
}
}
//
// Entry-point.
//
func (p *versionCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
showVersion(p.verbose)
return subcommands.ExitSuccess
}