Skip to content

fix(flags): parse all flags regardless of help flag position#38

Merged
seanseannery merged 1 commit intomainfrom
fix/help-flag-order
Mar 8, 2026
Merged

fix(flags): parse all flags regardless of help flag position#38
seanseannery merged 1 commit intomainfrom
fix/help-flag-order

Conversation

@seanseannery
Copy link
Owner

Key Changes

  • All help tokens (-h, --help, -?) are now stripped from args before fs.Parse, so pflag never short-circuits and all other flags are parsed regardless of position
  • Simplifies the previous split logic (separate -? pre-check + pflag.ErrHelp catch) into a single unified approach
  • 3 new test cases for help-before-flag ordering (--help -D, -h -D, -? -D)

Why do we need this?

pflag short-circuits when it encounters --help or -h, returning ErrHelp immediately without parsing any remaining flags. This meant --help -D /path would discard -D while -D /path --help worked correctly. Flag order should not matter.

Related to #19

New modules or other dependencies introduced

None

How was this tested?

  • 3 new unit tests verify -D is preserved when help flags appear before it
  • 3 existing tests verify -D is preserved when help flags appear after it
  • Manual smoke test: ops --help -D ./examples now shows the command listing
  • make lint and make test pass (all 91 tests)

Strip -h, --help, and -? from args before pflag parsing so that flags
appearing after the help flag are still parsed. Previously --help -D
would short-circuit pflag and discard -D.
@seanseannery seanseannery merged commit 70fb541 into main Mar 8, 2026
4 checks passed
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