Skip to content

✨ Enhance command alias handling and display#1422

Open
pipinstalled wants to merge 27 commits intofastapi:masterfrom
pipinstalled:feature/CommandAliases
Open

✨ Enhance command alias handling and display#1422
pipinstalled wants to merge 27 commits intofastapi:masterfrom
pipinstalled:feature/CommandAliases

Conversation

@pipinstalled
Copy link

  • 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
Copy link
Contributor

github-actions bot commented Nov 24, 2025

@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
Copy link
Member

@svlandeg svlandeg left a comment

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
Copy link
Author

pipinstalled commented Nov 25, 2025

@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
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.

@pipinstalled
Copy link
Author

@svlandeg Thanks for your help, fixed with adding new tests.

@pipinstalled pipinstalled marked this pull request as ready for review November 26, 2025 07:09
@pipinstalled
Copy link
Author

@svlandeg Have you any idea when this PR will merge? :D

@github-actions

This comment was marked as resolved.

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 25, 2025
@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Dec 25, 2025
@pipinstalled
Copy link
Author

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

@basnijholt
Copy link

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

@onyx-and-iris
Copy link

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.

Copy link
Member

@svlandeg svlandeg left a comment

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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, enhancement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for command and subcommand aliases

4 participants