From 9e45417ada86b5ad08a032219c9f84520d890d27 Mon Sep 17 00:00:00 2001 From: Ricardo Sawir <37329575+sawirricardo@users.noreply.github.com> Date: Fri, 12 Jun 2026 15:31:39 +0700 Subject: [PATCH] Fix --version over-propagation in check-cli-surface.sh The script merged ALL root flags (including local-only ones like --version) into every subcommand's flag list. Cobra adds --version as a local flag via InitDefaultVersionFlag, not a persistent one, so it does not inherit to subcommands. Fix: derive ROOT_FLAGS from a child command's inherited_flags instead of the root's .flags. This captures only the persistent subset that Cobra actually propagates to children. Closes #368 --- scripts/check-cli-surface.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/check-cli-surface.sh b/scripts/check-cli-surface.sh index b4fe9354..5fd58f87 100755 --- a/scripts/check-cli-surface.sh +++ b/scripts/check-cli-surface.sh @@ -15,7 +15,10 @@ fi # Capture root persistent flags once — these are available on every subcommand # but --help --agent only reports them on the root command itself. -ROOT_FLAGS=$("$BINARY" --help --agent 2>/dev/null | jq -c '[.flags // [] | .[] | {name, type}]') +# Use a child command's inherited_flags to get only persistent flags, excluding +# local-only root flags like --version that Cobra does not propagate. +_first_sub=$("$BINARY" --help --agent 2>/dev/null | jq -r '.subcommands[0].name') +ROOT_FLAGS=$("$BINARY" "${_first_sub}" --help --agent 2>/dev/null | jq -c '[.inherited_flags // [] | .[] | {name, type}]') walk_commands() { local cmd_path="$1"