Skip to content

Conversation

MorgenPronk
Copy link
Contributor

@MorgenPronk MorgenPronk commented Aug 5, 2025

This PR adds a note in the README explaining that Typer treats single-command CLIs differently than multi-command CLIs.

This behavior can be surprising for new users (like myself), because calling the command by name (e.g., python cli.py hello Camila) results in an error when only one command is defined — Typer silently expects python cli.py Camila instead.

While this is explained in the full documentation, the README contains a similar example and is often the first place beginners look. A brief clarification here could help save users some confusion — especially those coming from FastAPI, where the number of wrapped functions doesn’t affect how the app is invoked.

Related issues:

#315 - this PR directly addresses confusion raised here.

#445 - is tangentially related in that it also highlights behavioral differences when only one subcommand exists.

I’ve also explored making this behavior configurable (i.e., supporting both styles of invocation), and I’d be happy to help further if there’s interest. But this change is a simple, non-breaking way to surface the existing behavior earlier for new users.

Let me know if you'd prefer the note be placed elsewhere, want to reword it, or would like help drafting a fuller fix later on.

@MorgenPronk MorgenPronk marked this pull request as draft August 5, 2025 07:36
@github-actions github-actions bot added the docs Improvements or additions to documentation label Aug 7, 2025
@MorgenPronk MorgenPronk force-pushed the docs/single-command-note branch from 3eca414 to 4163446 Compare August 7, 2025 04:59

This comment was marked as outdated.

@MorgenPronk MorgenPronk marked this pull request as ready for review August 7, 2025 05:09
@svlandeg svlandeg changed the title docs: clarify single-command vs multi-command behaviour in README 📝 Clarify single-command vs multi-command behaviour in README Aug 18, 2025

This comment was marked as outdated.

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!

I think I would personally move this note to after the part where python main.py hello Camila and python main.py goodbye Camila are executed - i.e. right before the section "recap". I would also try to make the note as short as possible, while referring to the more detailed section.

@MorgenPronk MorgenPronk force-pushed the docs/single-command-note branch from 114718c to 75b8db6 Compare September 9, 2025 19:15

This comment was marked as outdated.

@MorgenPronk
Copy link
Contributor Author

updated the PR based on @svlandeg’s feedback:

  • Moved the note to right before the Recap section.
  • Simplified the wording as suggested.
  • Adjusted the formatting so it matches the style of other notes in the README.
    I also regenerated README.md from docs/index.md again.

Let me know if you’d like me to tweak the formatting further!

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.

This looks good to me. While I know we want to be mindful of keeping this page nice and short, I definitely can see how the difference between single and multi command usage is confusing, and a (relatively quick) note to address that seems like a good idea to me.

As always I'll defer to Tiangolo for the final decision though.

Copy link
Contributor

📝 Docs preview for commit ef31145 at: https://40a5e995.typertiangolo.pages.dev

Modified Pages

Copy link
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

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

Sounds good, thanks @MorgenPronk! ☕

And thanks for the help @svlandeg and @YuriiMotov 🍰

@tiangolo tiangolo merged commit e4c28a4 into fastapi:master Sep 20, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single @app.command() doesn't require me to pass function name in CLI
4 participants