Skip to content

✨ Enhance command alias handling and display#1422

Closed
pipinstalled wants to merge 30 commits into
fastapi:masterfrom
pipinstalled:feature/CommandAliases
Closed

✨ Enhance command alias handling and display#1422
pipinstalled wants to merge 30 commits into
fastapi:masterfrom
pipinstalled:feature/CommandAliases

Conversation

@pipinstalled

Copy link
Copy Markdown
  • Added support for positional and additional aliases in the command decorator.
  • Updated format_commands to display command names along with their visible aliases.
  • Improved command listing to maintain original order and avoid duplicates.
  • Enhanced command info structure to include aliases and hidden aliases.

This improves the usability and clarity of command help output.

pipinstalled and others added 4 commits November 23, 2025 22:22
- Added support for positional and additional aliases in the command decorator.
- Updated `format_commands` to display command names along with their visible aliases.
- Improved command listing to maintain original order and avoid duplicates.
- Enhanced command info structure to include aliases and hidden aliases.

This improves the usability and clarity of command help output.
…r into feature/CommandAliases

fix some type errors in github actions
@pipinstalled pipinstalled changed the title ✨ Enhance command alias handling and display in Typer issue #1242 ✨ Enhance command alias handling and display in Typer issue #1242 #feature Nov 23, 2025
@pipinstalled pipinstalled changed the title ✨ Enhance command alias handling and display in Typer issue #1242 #feature ✨ Enhance command alias handling and display in Typer issue #1242 Nov 23, 2025
@pipinstalled
pipinstalled marked this pull request as draft November 23, 2025 19:15
@github-actions

github-actions Bot commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

@pipinstalled
pipinstalled marked this pull request as ready for review November 24, 2025 09:45
@pipinstalled pipinstalled changed the title ✨ Enhance command alias handling and display in Typer issue #1242 ✨ Enhance command alias handling and display in Typer #1242 Nov 24, 2025
@svlandeg svlandeg linked an issue Nov 24, 2025 that may be closed by this pull request
@svlandeg svlandeg added the feature New feature, enhancement or request label Nov 24, 2025
@svlandeg svlandeg changed the title ✨ Enhance command alias handling and display in Typer #1242 ✨ Enhance command alias handling and display Nov 24, 2025

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pipinstalled: you can go ahead and set add # pragma: no cover to the pass statements in the tests, otherwise the coverage check will keep failing.

@svlandeg
svlandeg marked this pull request as draft November 25, 2025 15:22
@pipinstalled

pipinstalled commented Nov 25, 2025

Copy link
Copy Markdown
Author

@pipinstalled: you can go ahead and set add # pragma: no cover to the pass statements in the tests, otherwise the coverage check will keep failing.

@svlandeg I added # pragma but still coverage failed

@svlandeg

Copy link
Copy Markdown
Member

@pipinstalled: you can go ahead and set add # pragma: no cover to the pass statements in the tests, otherwise the coverage check will keep failing.

@svlandeg I added # pragma but still coverage failed

You'll have to look into the specifics of the coverage report. What this typically means is that there's a code path that is untested, so you'd have to implement more tests to cover it.

@github-actions github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Dec 25, 2025
@pipinstalled

Copy link
Copy Markdown
Author

@tiangolo Do you have any idea when this PR will merge? :)

@basnijholt

Copy link
Copy Markdown

This is great! Right now I am hacking around it (basnijholt/compose-farm#148).

@onyx-and-iris

Copy link
Copy Markdown

This will be great, I went the route of creating a custom alias class but I recently realised it broke shell completion :/ Thanks for all the efforts you've gone to with this PR.

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR, @pipinstalled!

I can see how it can be useful to define an alias for a given command.

In this specific PR, there are two ways implemented to accomplish that: either by positional arguments, or using an aliases= parameter. I'm not usually keen on implementing different ways of accomplishing the same thing: it creates confusion for users and unnecessary code maintenance.

Further, there is already a way (on master) to register different names for the same command:

@app.command("list")
@app.command("ls")
@app.command("listthem", hidden=True)
def list_items():
    print("Listing items")

I know that that would show up slightly differently in the help, they would show up as separate commands. At the same time I do also worry that this PR adds a new format_commands function and edits the Rich formatting in _print_commands_panel - it feels like these are potential cases for regressions or future issues.

TLDR: I'm not convinced that this a feature we'll want to support, especially considering the amount of changes needed in core etc. I'll run this by Tiangolo though, to see what he thinks.

Comment on lines +14 to +17
assert "list" in result.output or "ls" in result.output
assert (
"remove" in result.output or "rm" in result.output or "delete" in result.output
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should all be and instead of or, right?

@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 10, 2026
@github-actions

This comment was marked as resolved.

@svlandeg svlandeg self-assigned this Feb 22, 2026
@github-actions github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 24, 2026
@svlandeg svlandeg removed their assignment Feb 24, 2026
@pipinstalled

Copy link
Copy Markdown
Author

@svlandeg Thanks for the review!

That makes sense. I didn’t mean to introduce two different ways of doing the same thing — that’s definitely not ideal long term.

My main goal was to allow defining aliases while keeping them grouped as a single logical command in the help output. The existing decorator approach works, but it shows them as separate commands, which can get a bit noisy in larger CLIs.

If having both positional aliases and aliases= feels redundant, I’m totally fine simplifying this and keeping just one approach.

About the changes in format_commands and _print_commands_panel: fair point. I can take another look and see if there’s a way to reduce the surface of those changes.

Happy to adjust this based on your and @tiangolo’s thoughts.

@onyx-and-iris

Copy link
Copy Markdown

I definitely agree on just one way to define aliases, my vote would go towards the aliases= keyword.

I would also like to see an improvement on the default way of defining them. Defining multiple decorators and then hiding them from the help output seems less than ideal.

@svlandeg

Copy link
Copy Markdown
Member

If having both positional aliases and aliases= feels redundant, I’m totally fine simplifying this and keeping just one approach.

About the changes in format_commands and _print_commands_panel: fair point. I can take another look and see if there’s a way to reduce the surface of those changes.

I think doing both of these would help increase this PR's chances of getting reviewed by Tiangolo & (hopefully) merged. I agree with @onyx-and-iris, to me the aliases keyword also seems like the nicest approach.

@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label May 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

@github-actions

Copy link
Copy Markdown
Contributor

Heads-up: this will be closed in 3 days unless there's new activity.

@github-actions

Copy link
Copy Markdown
Contributor

This has been waiting for the original user for a while and seems to be inactive, so it will be closed now. If there's still interest, feel free to start a new conversation.

@github-actions github-actions Bot closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature, enhancement or request waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for command and subcommand aliases

5 participants