Skip to content

Refuse an option alias that a standard switch or another option already owns - #34

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/reject-clashing-aliases-18
Oct 7, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/reject-clashing-aliases-18

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #18

What changed

  • TrayAppBuilder.Flag and TrayAppBuilder.Option now throw ArgumentException when an alias can never be reached. That covers two cases:

    • The alias is a standard switch: -t, --tray, --no-tray, -s, --status, -h, --help, -?, -v, --version, -f or --for.
    • An earlier app option already registered the alias. The check uses the ordinal comparison that AppOption.Matches uses.

    The message names the conflicting alias, and ParamName is aliases.

  • The reserved spellings are in CommandLineParser.StandardAliases (internal), next to the switch that reads them. Before this, a tool registering -s, --silent got --status behaviour, and --help listed both options.

Tests

  • Flag_WithAStandardSwitchAlias_Throws is data-driven over the standard switches. Option_WithAStandardSwitchAlias_Throws and Flag_WithAnAliasAnotherOptionTook_Throws each check that the message names the alias. The last one also checks that the rejected option is not registered.
  • I ran the new tests against main's builder: all 11 fail there and pass with this change.
  • Full suite: 136 passed, 1 skipped (the same test that was skipped before), 0 failed. The solution build, which includes the demo, is clean.

Note

This is a behaviour change for any tool that registers a clashing alias today. Those tools now fail when the builder runs, instead of silently losing the option. That outcome is what the issue asks for.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SwBwi3NknT7dGVuSEED1DX


Generated by Claude Code

…dy owns

The parser reads the standard switches before any application option and
resolves application options first-match, so a Flag or Option spelled -s,
--for, or like an earlier option could never be reached, while --help
listed both. Flag and Option now throw ArgumentException naming the alias.

Fixes #18

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwBwi3NknT7dGVuSEED1DX
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 5f7dc79 into main Oct 7, 2026
14 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.

An app option whose alias clashes with a built-in switch (-s, -f, -t, -h, -v, -?) or another app option is silently unreachable, while --help lists both

2 participants