Skip to content

fix(flags): preserve parsed flags when --help is combined with -D#37

Merged
seanseannery merged 1 commit intomainfrom
fix/help-directory-flag-issue-19
Mar 7, 2026
Merged

fix(flags): preserve parsed flags when --help is combined with -D#37
seanseannery merged 1 commit intomainfrom
fix/help-directory-flag-issue-19

Conversation

@seanseannery
Copy link
Owner

Key Changes

  • ParseOpsFlags now returns populated OpsFlags alongside ErrHelp instead of a zero-value struct, so flags like -D parsed before --help/-h/-? are preserved
  • The -? handler now strips -? from args and still runs fs.Parse on the remaining flags before returning ErrHelp
  • 3 new test cases verify -D is preserved when combined with each help variant (--help, -h, -?)
  • Test harness updated to assert on wantFlags even in error cases

Why do we need this?

When -D /path --help was passed, the --help path in main.go used flags.Directory to locate the Opsfile for the command listing. But ParseOpsFlags was returning OpsFlags{} (zero value) on all help paths, so flags.Directory was always empty and the Opsfile was never found. This broke the --help + -D integration added in #36.

Related to #19

New modules or other dependencies introduced

None

How was this tested?

  • 3 new unit tests: -D combined with --help, -D combined with -h, -D combined with -? — all verify OpsFlags.Directory is populated alongside ErrHelp
  • Manual smoke test: ops -D ./examples --help now shows the command listing
  • make lint and make test pass

ParseOpsFlags was returning a zero-value OpsFlags when ErrHelp was
triggered, discarding any flags parsed before --help/-h/-?. This caused
the --help path in main.go to ignore -D and fail to find the Opsfile.
@seanseannery seanseannery merged commit 69c57e2 into main Mar 7, 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