2
私が達成したいのは、引数がある特定の事前定義されたセット(ここではtool1、tool2、tool3)の一部であり、@click.option
とtype=click.Choice()
のように、同時に@click.argument
とnargs=-1
のような複数の引数を渡すことができます。click.Choice複数の引数
import click
@click.command()
@click.option('--tools', type=click.Choice(['tool1', 'tool2', 'tool3']))
@click.argument('programs', nargs=-1)
def chooseTools(programs, tools):
"""Select one or more tools to solve the task"""
# Selection of only one tool, but it is from the predefined set
click.echo("Selected tools with 'tools' are {}".format(tools))
# Selection of multiple tools, but no in-built error handling if not in set
click.echo("Selected tools with 'programs' are {}".format(programs))
これは、このような例を探します:
python selectTools.py --tools tool1 tool3 tool2 nonsense
Selected tools with 'tools' are tool1
Selected tools with 'programs' are (u'tool3', u'tool2', u'nonsense')
それを達成するためのクリックで任意の組み込みの方法はありますか? または、@click.argument
を使用して、機能自体の入力を確認する必要がありますか?
私は、コマンドラインインターフェイスをプログラミングするのはむしろ、クリックだけではなく、Pythonで深く掘り下げることを始めたばかりであり、この問題をきちんとした方法で処理するための推奨事項に感謝します。