-
Is your feature request related to a problemCurrently there's no way to split commands in the same group / subcommand into different files easily. The solution you would likeI'm thinking of making it so when Example:
import typer
app = typer.Typer()
@app.command()
def create(item: str):
typer.echo(f"Creating item: {item}")
import typer
app = typer.Typer()
@app.command()
def delete(item: str):
typer.echo(f"Deleting item: {item}")
import typer
import create
import delete
app = typer.Typer()
app.add_typer(create.app)
app.add_typer(delete.app) Output: $ python main.py --help
Usage: main.py items [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
create
delete Additional contextCurrently giving no name to |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
I was looking to do something similar and had an idea (currently untested). If you put the various commands into their own files as raw functions, then you can import them into your e.g.
|
Beta Was this translation helpful? Give feedback.
-
@lllama I currently just do this import typer
import create
import delete
app = typer.Typer()
app.registered_commands += create.app.registered_commands + delete.app.registered_commands I don't currently have the original code, so this may not be exactly what I wrote, but you get the idea. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this! I am working on a little Typer app and I wanted to write my commands modularly with the style shown here, since the docs mention that Typer can recognize when a Typer app has only one command using a pattern like in your snippet lets me define my commands in separate files, compose them into the main application, and avoid having redundant nesting in the command hierarchy 👍🏻 I think it would be a great feature if Typer could emulate this directly when it observes that a sub-Typer has only one command. It seems strange that possibly related: #119 |
Beta Was this translation helpful? Give feedback.
-
This is same same but less typing in the " |
Beta Was this translation helpful? Give feedback.
-
We just released typer 0.15.0 which allows to do this using Here's the docs: https://typer.tiangolo.com/tutorial/one-file-per-command/ :D |
Beta Was this translation helpful? Give feedback.
We just released typer 0.15.0 which allows to do this using
add_typer
😊Here's the docs: https://typer.tiangolo.com/tutorial/one-file-per-command/ :D