Skip to content

Fix --version over-propagation in check-cli-surface.sh #368

@jeremy

Description

@jeremy

Background

scripts/check-cli-surface.sh merges $ROOT_FLAGS (all root command flags) into every subcommand's flag list at line 45:

ROOT_FLAGS=$("$BINARY" --help --agent 2>/dev/null | jq -c '[.flags // [] | .[] | {name, type}]')
# ...
((.flags // []) + (.inherited_flags // []) + $root | group_by(.name) | map(.[0]) | sort_by(.name))

This incorrectly propagates --version to all subcommands. Cobra adds --version as a local flag on the root (via InitDefaultVersionFlag), not a persistent one — it does not inherit to subcommands.

Impact

The Go surface walker (github.com/basecamp/cli/surface v0.2.1) correctly omits --version from subcommands. This creates a 612-entry divergence between the shell script and the Go walker. Documented in PR #366.

Fix

Change $ROOT_FLAGS to only include root persistent flags, not all root flags. The --help --agent JSON already distinguishes .flags from .inherited_flags — filter $ROOT_FLAGS to only the persistent subset, or use inherited_flags from the root's children instead of force-merging root flags.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions