From dcc1a1a637a5f6e02be48c4b583848aa31f5cac7 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 20 Sep 2024 17:57:18 +0200 Subject: [PATCH] Use cobra's version flag support Assigning a value to the Version field in the root cobra command automatically defines a --version flag which displays the command name and version, in much the same way as "subctl version" does already. This provides version information in a fashion aligned with common practice. Signed-off-by: Stephen Kitt --- cmd/subctl/root.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/subctl/root.go b/cmd/subctl/root.go index 9cad3d40b..394d9feb8 100644 --- a/cmd/subctl/root.go +++ b/cmd/subctl/root.go @@ -31,6 +31,7 @@ import ( "github.com/submariner-io/shipyard/test/e2e/framework" "github.com/submariner-io/subctl/internal/exit" "github.com/submariner-io/subctl/pkg/cluster" + "github.com/submariner-io/subctl/pkg/version" submarineropv1a1 "github.com/submariner-io/submariner-operator/api/v1alpha1" submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1" "golang.org/x/net/http/httpproxy" @@ -64,8 +65,9 @@ func init() { // rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ - Use: filepath.Base(os.Args[0]), - Short: "Deploy, manage, verify and diagnose Submariner deployments", + Use: filepath.Base(os.Args[0]), + Short: "Deploy, manage, verify and diagnose Submariner deployments", + Version: version.Version, } // Execute adds all child commands to the root command and sets flags appropriately.