Replies: 1 comment
-
It seems you're trying to invoke multiple subcommands simultaneously within a single command line using typer. I am not an expert of typer, but I don't think it natively support invoking multiple subcommands in one command line. What are you trying to achieve? In a typical command-line interface, subcommands are designed to be mutually exclusive, meaning that only one subcommand can be executed at a time per command invocation. When you run: $ python main.py users create "user name" items create "item name" Typer interprets If you absolutely need to execute multiple actions in a single command, you can implement a command that processes multiple "subcommands" (actually arguments of your command). Here’s an example of how you could implement this: import typer
app = typer.Typer()
@app.command("multi")
def multi_command(users_create: str = None, items_create: str = None):
if users_create:
typer.echo(f"Creating user: {users_create}")
# Logic to create a user
if items_create:
typer.echo(f"Creating item: {items_create}")
# Logic to create an item
if __name__ == "__main__":
app() You would then run: $ python main.py --users-create "user name" --items-create "item name" Let me know if this helps or if you need further assistance. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I need a cli with several subcommands that are invoked simultaneously. I followed the SubCommands in a Single File, but it creates mutually exclusive commands that cannot be invoked in one command line.
Following the example from the above tutorial, such command would look like this:
It fails with an error:
Got unexpected extra arguments (items create item name)
Is it possible to achieve this with
typer
?Operating System
Linux
Operating System Details
No response
Typer Version
0.12.4
Python Version
3.11
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions