Skip to content

Commit d54eaaf

Browse files
committed
runc --version: use a function
Instead of setting cli.App.Version in main, let's set up cli.VersionPrinter. This way, we only get various versions when needed. Note it does not change the output of runc --version. It changes the output of runc --help though, and I think it's for the better. Before this patch: > $ runc help > ... > USAGE: > runc [global options] command [command options] [arguments...] > > VERSION: > 1.3.0-rc.1+dev > commit: v1.3.0-rc.1-93-g932e8342 > spec: 1.2.1 > go: go1.24.2 > libseccomp: 2.5.5 > > COMMANDS: > checkpoint checkpoint a running container > ... After: > $ runc help > ... > USAGE: > runc [global options] command [command options] [arguments...] > > VERSION: > 1.3.0-rc.1+dev > > COMMANDS: > checkpoint checkpoint a running container > ... Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent a3a8a2e commit d54eaaf

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

main.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ var version = "unknown"
2727
// and will be populated by the Makefile
2828
var gitCommit = ""
2929

30+
func printVersion(c *cli.Context) {
31+
w := c.App.Writer
32+
33+
fmt.Fprintln(w, "runc version", c.App.Version)
34+
if gitCommit != "" {
35+
fmt.Fprintln(w, "commit:", gitCommit)
36+
}
37+
fmt.Fprintln(w, "spec:", specs.Version)
38+
fmt.Fprintln(w, "go:", runtime.Version())
39+
40+
major, minor, micro := seccomp.Version()
41+
if major+minor+micro > 0 {
42+
fmt.Fprintf(w, "libseccomp: %d.%d.%d\n", major, minor, micro)
43+
}
44+
}
45+
3046
const (
3147
specConfig = "config.json"
3248
usage = `Open Container Initiative runtime
@@ -57,21 +73,10 @@ value for "bundle" is the current directory.`
5773
func main() {
5874
app := cli.NewApp()
5975
app.Name = "runc"
76+
app.Version = version
6077
app.Usage = usage
6178

62-
v := []string{version}
63-
64-
if gitCommit != "" {
65-
v = append(v, "commit: "+gitCommit)
66-
}
67-
v = append(v, "spec: "+specs.Version)
68-
v = append(v, "go: "+runtime.Version())
69-
70-
major, minor, micro := seccomp.Version()
71-
if major+minor+micro > 0 {
72-
v = append(v, fmt.Sprintf("libseccomp: %d.%d.%d", major, minor, micro))
73-
}
74-
app.Version = strings.Join(v, "\n")
79+
cli.VersionPrinter = printVersion
7580

7681
root := "/run/runc"
7782
xdgDirUsed := false

0 commit comments

Comments
 (0)