From 4a2113e08abb45949e825362f5faad2683851ef9 Mon Sep 17 00:00:00 2001 From: A Tobey Date: Sun, 9 Nov 2025 20:11:48 +0000 Subject: [PATCH] feat: add --version flag to root command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: Users expect --version flag as standard CLI pattern (issue #9) Approach: Set rootCmd.Version in createRootCmd, add functional tests Learned: Cobra auto-adds -v/--version when Version field is set Next: Create PR and close issue Changes: - Added rootCmd.Version = config.Version in createRootCmd() - Added functional tests for both 'version' subcommand and '--version' flag - Tests verify output format and exit code - All tests pass Fixes #9 🤖 Claude --- data_for_test.go | 25 +++++++++++++++++++++++++ otelcli/root.go | 1 + 2 files changed, 26 insertions(+) diff --git a/data_for_test.go b/data_for_test.go index 8250e15..4cc86bf 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -1373,4 +1373,29 @@ var suites = []FixtureSuite{ }, }, }, + // version flag tests + { + { + Name: "version subcommand", + Config: FixtureConfig{ + CliArgs: []string{"version"}, + }, + Expect: Results{ + CliOutput: "\n", + CliOutputRe: regexp.MustCompile(`\S+`), + ExitCode: 0, + }, + }, + { + Name: "--version flag", + Config: FixtureConfig{ + CliArgs: []string{"--version"}, + }, + Expect: Results{ + CliOutput: "\n", + CliOutputRe: regexp.MustCompile(`otel-cli version \S+`), + ExitCode: 0, + }, + }, + }, } diff --git a/otelcli/root.go b/otelcli/root.go index db8ba6c..7b3830a 100644 --- a/otelcli/root.go +++ b/otelcli/root.go @@ -59,6 +59,7 @@ func createRootCmd(config *Config) *cobra.Command { cobra.EnableCommandSorting = false rootCmd.Flags().SortFlags = false + rootCmd.Version = config.Version Diag.NumArgs = len(os.Args) - 1 Diag.CliArgs = []string{}