Skip to content
Myr

📝 Update AI Library Skill to avoid verbose code for CLI Options (#1808)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent e9efaab · Browse files · 1 file+23 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−1 removed

  • other:+23 added−1 removed

1 file+23 added−1 removed

modified:typer/.agents/skills/typer/SKILL.md+23 added-1 removed
123 unmodified lines
124```125126## CLI Options127128CLI options are declared in a similar fashion as arguments, but will be called on the CLI with a single dash (single letter) or 2 dashes (full name):128CLI options are declared in a similar fashion as arguments, but will be called on the CLI with a single dash (single letter) or 2 dashes (full name).129130The CLI option name is automatically generated from the variable name, so `user_name` becomes `--user-name` automatically:131132```python133from typing import Annotated134135import typer
1 unmodified line
137app = typer.Typer()138139140@app.command()141def main(user_name: Annotated[str, typer.Option()]):142 # On the CLI, the required user name can be specified with --user-name143 print(f"Hello {user_name}")144145146if __name__ == "__main__":147 app()148```149150If you want to specify a different name, or want to add a short version, declare them in the `typer.Option`:151152```python153from typing import Annotated154155import typer156157app = typer.Typer()158159160@app.command()161def main(user_name: Annotated[str, typer.Option("--name", "-n")]):162 # On the CLI, the required user name can be specified with -n or --name163 print(f"Hello {user_name}")164
124 unmodified lines