【发布时间】:2022-01-26 01:07:21
【问题描述】:
我的命令行应用中有这个命令add。
@app.command(name="add")
def add(
priority: int = typer.Argument(...),
description: List[str] = typer.Argument(...),
) -> None:
print(description)
"""Add a new task with a DESCRIPTION."""
todoer = get_todoer()
todo, error = todoer.add(description, priority)
if error:
typer.secho(
f'Adding task failed with "{ERRORS[error]}"', fg=typer.colors.RED
)
raise typer.Exit(1)
else:
typer.secho(
f"""Added task: "{todo['Description']}" """
f"""with priority {priority}""",
fg=typer.colors.GREEN,
)
它应该阅读任何长度的描述。但问题是它在第一个空格之后停止读取。
(venv) C:\Users\Asus\Desktop\fellowship-python\python>.\task add 10 Buy Milk
('Buy',)
Added task: "Buy" with priority 10
(venv) C:\Users\Asus\Desktop\fellowship-python\python>
如何在 add 命令中读取多个未知数量的参数作为参数。
【问题讨论】:
标签: python python-3.x command-line-interface command-line-arguments typer