Skip to content

Add support for synonyms in subcommands and options#208

Open
ianloic wants to merge 2 commits intogoogle:masterfrom
ianloic:synonyms
Open

Add support for synonyms in subcommands and options#208
ianloic wants to merge 2 commits intogoogle:masterfrom
ianloic:synonyms

Conversation

@ianloic
Copy link

@ianloic ianloic commented Dec 23, 2025

This commit introduces the synonyms attribute to #[argh()], allowing users to specify alternative names for subcommands, options, and switches. Synonyms are hidden from the help output but are accepted during parsing.

Key changes:

  • Added synonyms = ["..."] attribute support in argh_derive.
  • Extended SubCommand trait with SYNONYMS constant.
  • Extended SubCommands trait with COMMAND_SYNONYMS constant.
  • Updated ParseStructSubCommand::parse to check synonyms.
  • Updated documentation with examples.

This implementation avoids breaking changes to the public CommandInfo API by storing synonym information in the SubCommand trait instead.

This commit introduces the `synonyms` attribute to `#[argh()]`, allowing
users to specify alternative names for subcommands, options, and
switches.  Synonyms are hidden from the help output but are accepted
during parsing.

Key changes:
- Added `synonyms = ["..."]` attribute support in argh_derive.
- Extended `SubCommand` trait with `SYNONYMS` constant.
- Extended `SubCommands` trait with `COMMAND_SYNONYMS` constant.
- Updated `ParseStructSubCommand::parse` to check synonyms.
- Updated documentation with examples.

This implementation avoids breaking changes to the public `CommandInfo`
API by storing synonym information in the `SubCommand` trait instead.
Copy link
Collaborator

@erickt erickt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

);
errors.err_span_tokens(field.field, "Later usage here.");
}
// Synonyms are treated as long names, so we don't check against short names unless we want to support short synonyms (which we don't seem to support explicitly as short flags).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this comment?

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.

2 participants