Repository navigation
Replies: 1 comment
|
Make import typer
app = typer.Typer()
user_app = typer.Typer()
update_app = typer.Typer()
@user_app.callback()
def select_user(ctx: typer.Context, email: str):
ctx.ensure_object(dict)
ctx.obj["email"] = email
@update_app.command()
def password(ctx: typer.Context, password: str):
email = ctx.obj["email"]
# Call your update routine with email and password here.
typer.echo(f"Updating user {email}")
user_app.add_typer(update_app, name="update")
app.add_typer(user_app, name="user")
if __name__ == "__main__":
app()This accepts your requested shape: python main.py user test@example.com update password synthetic-exampleIn the original version, I checked the full command path and rejection of a missing email with |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
I think that the pattern I want to achieve is pretty straightforward. I would like to be able to define subcommand to
app, but force user to pass some argument before subcommand. In this example I want to haveuserto act as a selector of some particular user before I follow with subcommands. So my expected behavior is to be able to do:python3 main.py user "test@test.com" update password "qwerty"Currently it just show "update" as one of the commands of the main program.
Operating System
macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.11.6
Additional Context
No response
All reactions