-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathversion_cmd.go
59 lines (48 loc) · 986 Bytes
/
version_cmd.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
//
// Show our version.
//
package main
import (
"flag"
"fmt"
"io"
"os"
"runtime"
)
//
// modified during testing
//
var out io.Writer = os.Stdout
var (
version = "unreleased"
)
// Structure for our options and state.
type versionCmd struct {
// verbose controls whether our version information includes
// the go-version.
verbose bool
}
// Info is part of the subcommand-API.
func (v *versionCmd) Info() (string, string) {
return "version", `Report upon our version, and exit.`
}
// Arguments handles our flag-setup.
func (v *versionCmd) Arguments(f *flag.FlagSet) {
f.BoolVar(&v.verbose, "verbose", false, "Show go version the binary was generated with.")
}
//
// Show the version - using the "out"-writer.
//
func showVersion(verbose bool) {
fmt.Fprintf(out, "%s\n", version)
if verbose {
fmt.Fprintf(out, "Built with %s\n", runtime.Version())
}
}
//
// Entry-point.
//
func (v *versionCmd) Execute(args []string) int {
showVersion(v.verbose)
return 0
}