From 5fde7662f1a5ec0ee776abe77dbec032f3957510 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 7 Feb 2026 12:44:28 +0100 Subject: [PATCH 1/3] cmd/*: don't print default value for '--help' and '--version' Remove the confusing `(default: false)` that's printed. Before this: ctr --help | tail -n2 --help, -h Show help (default: false) --version, -v Print the version (default: false) After this: ctr --help | tail -n2 --help, -h Show help --version, -v Print the version Signed-off-by: Sebastiaan van Stijn --- cmd/containerd-stress/main.go | 2 ++ cmd/containerd/command/main.go | 7 +++++++ cmd/ctr/app/main.go | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index 5739b0f2de4c5..eded65ca1c552 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -68,6 +68,8 @@ func init() { Name: "help", Aliases: []string{"h"}, Usage: "Show help", + + DisableDefaultText: true, } } diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index c4d58c1322f72..94d590af2efb7 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -57,15 +57,22 @@ func init() { cli.VersionPrinter = func(cliContext *cli.Context) { fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version, version.Revision) } + + // Override the default flag descriptions for '--version' and '--help' + // to align with other flags and start with uppercase. cli.VersionFlag = &cli.BoolFlag{ Name: "version", Aliases: []string{"v"}, Usage: "Print the version", + + DisableDefaultText: true, } cli.HelpFlag = &cli.BoolFlag{ Name: "help", Aliases: []string{"h"}, Usage: "Show help", + + DisableDefaultText: true, } } diff --git a/cmd/ctr/app/main.go b/cmd/ctr/app/main.go index 13ec27635df57..d03ba9b94a2f9 100644 --- a/cmd/ctr/app/main.go +++ b/cmd/ctr/app/main.go @@ -55,15 +55,22 @@ func init() { cli.VersionPrinter = func(cliContext *cli.Context) { fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version) } + + // Override the default flag descriptions for '--version' and '--help' + // to align with other flags and start with uppercase. cli.VersionFlag = &cli.BoolFlag{ Name: "version", Aliases: []string{"v"}, Usage: "Print the version", + + DisableDefaultText: true, } cli.HelpFlag = &cli.BoolFlag{ Name: "help", Aliases: []string{"h"}, Usage: "Show help", + + DisableDefaultText: true, } } From 0edde8fde85e8a6a38fb1e2f870b0a45d2d1955c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 7 Feb 2026 12:58:32 +0100 Subject: [PATCH 2/3] cmd/containerd-stress: enable '--version' flag All other binaries have a `-v` and/or `--version` flag, which can be useful to perform a quick check if the binary is "functional". Before this: containerd-stress --version | tail -n1 flag provided but not defined: -version --help, -h Show help After this: containerd-stress --version | tail -n1 containerd-stress github.com/containerd/containerd/v2 v2.2.0-306-g2e46d7659.m containerd-stress --help | tail -n1 --version, -v Print the version Signed-off-by: Sebastiaan van Stijn --- cmd/containerd-stress/main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index eded65ca1c552..f8d0d0949ee72 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -33,6 +33,7 @@ import ( "github.com/containerd/containerd/v2/integration/remote" "github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/containerd/v2/version" "github.com/containerd/log" metrics "github.com/docker/go-metrics" "github.com/urfave/cli/v2" @@ -64,6 +65,19 @@ func init() { panic(err) } + cli.VersionPrinter = func(cliContext *cli.Context) { + fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version) + } + + // Override the default flag descriptions for '--version' and '--help' + // to align with other flags and start with uppercase. + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", + Aliases: []string{"v"}, + Usage: "Print the version", + + DisableDefaultText: true, + } cli.HelpFlag = &cli.BoolFlag{ Name: "help", Aliases: []string{"h"}, @@ -132,6 +146,7 @@ func main() { app := cli.NewApp() app.Name = "containerd-stress" app.Description = "stress test a containerd daemon" + app.Version = version.Version app.Flags = []cli.Flag{ &cli.BoolFlag{ Name: "debug", From e5ae0a8828e830b75bc51905bdfb5f11ef7d5f6d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 7 Feb 2026 13:08:41 +0100 Subject: [PATCH 3/3] cmd/shim: containerd-shim-runc-v2: add long-form '--version' flag All other binaries have both a `-v` and `--version` flag. Add a long-form '--version' flag for this binary, useful to perform a quick check if the binary is "functional". Before this: containerd-shim-runc-v2 --help # ... -socket string socket path to serve -v show the shim version and exit After this: containerd-shim-runc-v2 --help # ... -socket string socket path to serve -v -version show the shim version and exit Signed-off-by: Sebastiaan van Stijn --- pkg/shim/shim.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go index cc8da6f765478..2f93203c8f7dc 100644 --- a/pkg/shim/shim.go +++ b/pkg/shim/shim.go @@ -139,7 +139,12 @@ const ( func parseFlags() { flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs") - flag.BoolVar(&versionFlag, "v", false, "show the shim version and exit") + + // short + long form. omitting the usage (description) of the short-form + // to group it with the long form. + flag.BoolVar(&versionFlag, "v", false, "") + flag.BoolVar(&versionFlag, "version", false, "show the shim version and exit") + // "info" is not a subcommand, because old shims produce very confusing errors for unknown subcommands // https://github.com/containerd/containerd/pull/8509#discussion_r1210021403 flag.BoolVar(&infoFlag, "info", false, "get the option protobuf from stdin, print the shim info protobuf to stdout, and exit")