mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <kolyshkin@gmail.com>
This commit is contained in:
@@ -27,6 +27,22 @@ var version = "unknown"
|
||||
// and will be populated by the Makefile
|
||||
var gitCommit = ""
|
||||
|
||||
func printVersion(c *cli.Context) {
|
||||
w := c.App.Writer
|
||||
|
||||
fmt.Fprintln(w, "runc version", c.App.Version)
|
||||
if gitCommit != "" {
|
||||
fmt.Fprintln(w, "commit:", gitCommit)
|
||||
}
|
||||
fmt.Fprintln(w, "spec:", specs.Version)
|
||||
fmt.Fprintln(w, "go:", runtime.Version())
|
||||
|
||||
major, minor, micro := seccomp.Version()
|
||||
if major+minor+micro > 0 {
|
||||
fmt.Fprintf(w, "libseccomp: %d.%d.%d\n", major, minor, micro)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
specConfig = "config.json"
|
||||
usage = `Open Container Initiative runtime
|
||||
@@ -57,21 +73,10 @@ value for "bundle" is the current directory.`
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "runc"
|
||||
app.Version = version
|
||||
app.Usage = usage
|
||||
|
||||
v := []string{version}
|
||||
|
||||
if gitCommit != "" {
|
||||
v = append(v, "commit: "+gitCommit)
|
||||
}
|
||||
v = append(v, "spec: "+specs.Version)
|
||||
v = append(v, "go: "+runtime.Version())
|
||||
|
||||
major, minor, micro := seccomp.Version()
|
||||
if major+minor+micro > 0 {
|
||||
v = append(v, fmt.Sprintf("libseccomp: %d.%d.%d", major, minor, micro))
|
||||
}
|
||||
app.Version = strings.Join(v, "\n")
|
||||
cli.VersionPrinter = printVersion
|
||||
|
||||
root := "/run/runc"
|
||||
xdgDirUsed := false
|
||||
|
||||
Reference in New Issue
Block a user