-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
cmd_version_18.go
51 lines (37 loc) · 918 Bytes
/
cmd_version_18.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
//go:build go1.18
// +build go1.18
package main
import (
"fmt"
"runtime/debug"
"strings"
"github.com/skx/subcommands"
)
var (
version = "unreleased"
)
// Structure for our options and state.
type versionCommand struct {
// We embed the NoFlags option, because we accept no command-line flags.
subcommands.NoFlags
}
// Info returns the name of this subcommand.
func (t *versionCommand) Info() (string, string) {
return "version", `Show the version of this binary.
Details:
This reports upon the version of the application.
`
}
// Execute is invoked if the user specifies `version` as the subcommand.
func (t *versionCommand) Execute(args []string) int {
fmt.Printf("%s\n", version)
info, ok := debug.ReadBuildInfo()
if ok {
for _, settings := range info.Settings {
if strings.Contains(settings.Key, "vcs") {
fmt.Printf("%s: %s\n", settings.Key, settings.Value)
}
}
}
return 0
}