Fix --version over-propagation in check-cli-surface.sh#499
Open
sawirricardo wants to merge 1 commit into
Open
Conversation
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 basecamp#368
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the CLI surface-check script to detect only persistent (inherited) flags, avoiding root-only flags that don’t propagate to subcommands.
Changes:
- Switches ROOT_FLAGS extraction from
.flagson the root command to.inherited_flagson a child subcommand. - Adds logic to pick the first subcommand name from the root
--help --agentJSON output.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+18
to
+21
| # 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}]') |
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/check-cli-surface.shmerged ALL root.flags(22 entries) into every subcommand, including local-only flags like--versionthat Cobra does not propagate to children. This created a ~612-entry divergence vs the Go surface walker (github.com/basecamp/cli/surface).Fix
Derive
$ROOT_FLAGSfrom a child command'sinherited_flagsinstead of the root's.flags. This captures only the 5 persistent flags Cobra actually propagates (account,json,md,project,quiet), excluding 17 local-only flags (version,agent,verbose,cache-dir, etc.).Before → After
--versionin subcommand surfaceTesting
Closes #368
Summary by cubic
Fixes incorrect flag propagation in
scripts/check-cli-surface.shby only inheriting persistent flags for subcommands. This removes--versionand other local-only flags from subcommand surfaces and restores parity with the Go walkergithub.com/basecamp/cli/surface.ROOT_FLAGSfrom a subcommand’sinherited_flagsinstead of the root’s.flags.--versionis root-only; surface size drops from ~10,900 to ~7,750 lines.Written for commit 9e45417. Summary will update on new commits.