forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
57 lines (47 loc) · 1.04 KB
/
command.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
package version
import (
"flag"
"fmt"
"io"
"os"
"strings"
)
// These variables are populated via the Go linker.
var (
version string = "0.9"
commit string
)
func init() {
// If commit not set, make that clear.
if commit == "" {
commit = "unknown"
}
}
// Command represents the command executed by "influxd version".
type Command struct {
Stdout io.Writer
Stderr io.Writer
}
// NewCommand return a new instance of Command.
func NewCommand() *Command {
return &Command{
Stdout: os.Stdout,
Stderr: os.Stderr,
}
}
// Run prints the current version and commit info.
func (cmd *Command) Run(args ...string) error {
// Parse flags in case -h is specified.
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Usage = func() { fmt.Fprintln(cmd.Stderr, strings.TrimSpace(usage)) }
if err := fs.Parse(args); err != nil {
return err
}
// Print version info.
fmt.Fprintf(cmd.Stdout, "InfluxDB v%s (git: %s)\n", version, commit)
return nil
}
var usage = `
usage: version
version displays the InfluxDB version and build git commit hash
`