【发布时间】:2020-06-29 14:40:07
【问题描述】:
我想创建一个以kubectl 方式接收操作和资源参数的 CLI。例如。
myctl init config
myctl create issue|pr|branch
myctl delete issue|pr|branch|config
myctl 命令应该始终接收 2 个参数,这样用户就不会尝试类似:myctl init config delete issue。也不应该能够执行不可能的组合,例如myctl create config。
我想到了一些类似的代码:
import click
@click.command()
@click.group()
@click.option(
"init,create,delete",
type=str,
help="Action name.",
)
@click.option(
"config,issue,pr,branch",
type=str,
help="Resource name.",
)
def main(action: str, resource: str) -> None:
pass
if __name__ == "__main__":
main(prog_name="myctl")
我不确定我应该使用哪些点击元素来构建它(参数、选项、组等)以及如何将它们组合在一起。
【问题讨论】:
标签: python python-3.x command-line-interface python-click