1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
import typer
import typing as t
try:
from enum import StrEnum
except ImportError:
from enum import Enum
class StrEnum(str, Enum):
pass
from typing_extensions import Annotated
app = typer.Typer(add_completion=False)
class Kind(StrEnum):
ONE = "one"
TWO = "two"
@app.callback()
def callback(
arg: Annotated[Kind, typer.Argument(help="An argument.")],
flag: Annotated[bool, typer.Option(help="Flagged.")] = False,
switch: Annotated[
bool,
typer.Option("--switch", "-s", help="Switch.")
] = False
):
"""This is the callback function."""
pass
@app.command()
def foo(
name: Annotated[
str,
typer.Option(..., help="The name of the item to foo.")
]
):
"""This is the foo command."""
pass
@app.command()
def bar(
names: Annotated[
t.List[str],
typer.Option(..., help="The names of the items to bar.")
],
):
"""This is the bar command."""
pass
if __name__ == "__main__":
app()
|