Skip to content

Recognize -h/--help at any position and reserve them for help - #257

Merged
neuecc merged 1 commit into
masterfrom
fix/help-anywhere
Oct 26, 2026
Merged

neuecc merged 1 commit into
masterfrom
fix/help-anywhere

Conversation

@neuecc

@neuecc neuecc commented Oct 26, 2026

Copy link
Copy Markdown
Member

Fixes #248

Summary

-h / --help was only recognized when it was the single argument, so list --input foo --help failed with Argument '--help' is not recognized. even though the usage line shows [options...] [-h|--help].

Help at any position

  • TryShowHelpOrVersion (both ConsoleApp and ConsoleAppBuilder) now shows help when -h or --help appears anywhere before the -- escape.
  • --version is unchanged (recognized only when passed alone).
  • The cost is a single scan over args with string equality checks before parsing; no allocation.

CAF019: -h / --help are reserved

  • New compile error CAF019 when a parameter name (e.g. string help) or a doc comment alias (e.g. -h, host) is -h or --help.
  • Such options were already partially broken: they were shadowed by help when passed alone (app -h), but worked when combined with other arguments (app -h localhost). With help now recognized at any position they would always be shadowed, so this makes the conflict explicit at build time instead.
  • Class based commands (Add<T>) now also go through ValidateCommand so the check applies to them as well.

Breaking changes

  • Code that defines -h or --help (or a parameter named help) as an option now fails to build with CAF019.
  • A literal -h / --help can no longer be passed as an option value (e.g. --message --help) unless it is after --.
  • Global options (AddGlobalOption("-h|...")) are not checked at compile time; help takes precedence over them at runtime.

Tests

  • HelpTest: help at any position for Run, builder commands, with global options, and not recognized after --.
  • DiagnosticsTest: CAF019 for parameter name, short alias and long alias.
  • All 127 generator tests pass locally; the solution builds.

🤖 Generated with Claude Code

- TryShowHelpOrVersion now shows help when -h or --help appears anywhere
  before the "--" escape (e.g. `list --input foo --help`). --version is
  still recognized only when passed alone.
- Add CAF019 compile error when a parameter name or alias is -h or --help.
  Previously such options were shadowed by help only when passed alone.
- Class based commands (Add<T>) now also go through ValidateCommand.

Fixes #248

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

--help is not recognized when placed after command options

1 participant