Skip to content

Commit c909b59

Browse files
committed
Show more output on our "versione" sub-command
This is conditional on go 1.18 being present
1 parent bb1fe0c commit c909b59

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

cmd_version.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
//go:build !go1.18
2+
// +build !go1.18
3+
14
package main
25

3-
//go:generate echo Hello, Go Generate!
46
import (
57
"fmt"
6-
"runtime/debug"
7-
"strings"
88

99
"github.com/skx/subcommands"
1010
)
1111

1212
var (
13-
versionString = "unreleased"
13+
version = "unreleased"
1414
)
1515

1616
// Structure for our options and state.
@@ -22,34 +22,18 @@ type versionCommand struct {
2222

2323
// Info returns the name of this subcommand.
2424
func (t *versionCommand) Info() (string, string) {
25-
return "version", `Show the version of the binary.
25+
return "version", `Show the version of this binary.
2626
2727
Details:
2828
29-
This reports upon the version of the sysbox application.
30-
31-
Usage:
32-
33-
$ sysbox version
34-
29+
This reports upon the version of the application.
3530
`
3631
}
3732

3833
// Execute is invoked if the user specifies `version` as the subcommand.
3934
func (t *versionCommand) Execute(args []string) int {
4035

41-
fmt.Printf("%s\n", versionString)
42-
43-
// Show VCS information
44-
info, ok := debug.ReadBuildInfo()
45-
46-
if ok {
47-
for _, settings := range info.Settings {
48-
if strings.Contains(settings.Key, "vcs") {
49-
fmt.Printf("%s: %s\n", settings.Key, settings.Value)
50-
}
51-
}
52-
}
36+
fmt.Printf("%s\n", version)
5337

5438
return 0
5539
}

cmd_version_18.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"runtime/debug"
9+
"strings"
10+
11+
"github.com/skx/subcommands"
12+
)
13+
14+
var (
15+
version = "unreleased"
16+
)
17+
18+
// Structure for our options and state.
19+
type versionCommand struct {
20+
21+
// We embed the NoFlags option, because we accept no command-line flags.
22+
subcommands.NoFlags
23+
}
24+
25+
// Info returns the name of this subcommand.
26+
func (t *versionCommand) Info() (string, string) {
27+
return "version", `Show the version of this binary.
28+
29+
Details:
30+
31+
This reports upon the version of the application.
32+
`
33+
}
34+
35+
// Execute is invoked if the user specifies `version` as the subcommand.
36+
func (t *versionCommand) Execute(args []string) int {
37+
38+
fmt.Printf("%s\n", version)
39+
40+
info, ok := debug.ReadBuildInfo()
41+
42+
if ok {
43+
for _, settings := range info.Settings {
44+
if strings.Contains(settings.Key, "vcs") {
45+
fmt.Printf("%s: %s\n", settings.Key, settings.Value)
46+
}
47+
}
48+
}
49+
50+
return 0
51+
}

0 commit comments

Comments
 (0)