Skip to content

refactor: declare each command's flags exactly once#83

Merged
andyrewlee merged 1 commit into
mainfrom
audit/36-flags-declare-once
Jun 15, 2026
Merged

refactor: declare each command's flags exactly once#83
andyrewlee merged 1 commit into
mainfrom
audit/36-flags-declare-once

Conversation

@andyrewlee

Copy link
Copy Markdown
Owner

The 9 flag-bearing commands declared their flags TWICE: runXxx bound its own
FlagSet while flagsets.go mirrored the same flags in a constructor reached only
by help introspection -- so help could silently UNDER-report a flag Run accepts
(only a hand-maintained expectation table guarded against it). Make each
constructor the single declaration site: newXxxFlags(o *xxxOpts) binds an opts
struct via StringVar/BoolVar (so -m/--message, -a/--all, -f/--force keep
command-line last-wins), runXxx calls it and reads o.fields, and the no-arg
xxxFlagSet() wrapper feeds the same set to help. Now help reports exactly what
Run parses, by construction -- under- and over-report are both impossible, so
the expectation table is deleted and the false 'introspects the very flag set it
parses with' comments are now true. -a=false still disables modify's staging
(verified); -h/--json output and the help golden are unchanged.


Part of a 38-PR stacked diff (audit/01audit/38), reviewed and merged bottom-up. This PR is based on audit/35-model-inject-conflicts.

@andyrewlee andyrewlee force-pushed the audit/35-model-inject-conflicts branch from 1722238 to 61aba0f Compare June 15, 2026 06:50
The 9 flag-bearing commands declared their flags TWICE: runXxx bound its own
FlagSet while flagsets.go mirrored the same flags in a constructor reached only
by help introspection -- so help could silently UNDER-report a flag Run accepts
(only a hand-maintained expectation table guarded against it). Make each
constructor the single declaration site: newXxxFlags(o *xxxOpts) binds an opts
struct via StringVar/BoolVar (so -m/--message, -a/--all, -f/--force keep
command-line last-wins), runXxx calls it and reads o.fields, and the no-arg
xxxFlagSet() wrapper feeds the same set to help. Now help reports exactly what
Run parses, by construction -- under- and over-report are both impossible, so
the expectation table is deleted and the false 'introspects the very flag set it
parses with' comments are now true. -a=false still disables modify's staging
(verified); -h/--json output and the help golden are unchanged.
@andyrewlee andyrewlee changed the base branch from audit/35-model-inject-conflicts to main June 15, 2026 06:51
@andyrewlee andyrewlee force-pushed the audit/36-flags-declare-once branch from 4192998 to 68dee03 Compare June 15, 2026 06:51
@andyrewlee andyrewlee merged commit 8f378de into main Jun 15, 2026
4 checks passed
@andyrewlee andyrewlee deleted the audit/36-flags-declare-once branch June 15, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant