| 1 |
from enum import Enum |
| 2 |
from typing import Literal |
| 3 |
|
| 4 |
import typer |
| 5 |
|
| 6 |
import cyclopts |
| 7 |
|
| 8 |
|
| 9 |
class Environment(str, Enum): |
| 10 |
DEV = "dev_value" |
| 11 |
STAGING = "staging_value" |
| 12 |
PROD = "prod_value" |
| 13 |
|
| 14 |
|
| 15 |
typer_app = typer.Typer() |
| 16 |
|
| 17 |
|
| 18 |
@typer_app.command() |
| 19 |
def foo(env: Environment = Environment.DEV): |
| 20 |
env = env.name |
| 21 |
print(f"Using: {env}") |
| 22 |
|
| 23 |
|
| 24 |
print("Typer (Enum):") |
| 25 |
cmd = ["--env", "staging_value"] |
| 26 |
print(cmd) |
| 27 |
typer_app(cmd, standalone_mode=False) |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
cyclopts_app = cyclopts.App() |
| 32 |
|
| 33 |
|
| 34 |
@cyclopts_app.default() |
| 35 |
def foo(env: Environment = Environment.DEV): |
| 36 |
env = env.name |
| 37 |
print(f"Using: {env}") |
| 38 |
|
| 39 |
|
| 40 |
print("Cyclopts (Enum):") |
| 41 |
cmd = ["--env", "staging"] |
| 42 |
print(cmd) |
| 43 |
cyclopts_app(cmd) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
cyclopts_app = cyclopts.App() |
| 48 |
|
| 49 |
|
| 50 |
@cyclopts_app.default() |
| 51 |
def foo(env: Literal["dev", "staging", "prod"] = "staging"): |
| 52 |
print(f"Using: {env}") |
| 53 |
|
| 54 |
|
| 55 |
print("Cyclopts (Literal):") |
| 56 |
cmd = ["--env", "staging"] |
| 57 |
print(cmd) |
| 58 |
cyclopts_app(cmd) |
| 59 |
|