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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-02-07 12:58:32 +01:00
parent 5fde7662f1
commit 0edde8fde8

View File

@@ -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",