多个单词选项

Multiple words option

我目前正在尝试通过点击使用多词选项:

@click.command()
@click.option('--do-not-destroy', is_flag=True, default=False, 
              help='Do not destroy Selenium containers on exit')
@click.option('--run-tests', default=True, help="Run the tests.")
def main(do-not-destroy, run-tests):
    ...

通常,我想要一个名为 'do-not-destroy' 的选项。由于修饰函数的参数名应该是选项名,所以参数名应该是'do-not-destroy'.

显然,此参数名称无效。

有没有办法告诉 click 它应该用于某个选项的参数名称(例如 do_not_destroy)?

单击将带有破折号 (-) 的任何 options/arguments 映射到下划线 (_)。所以:

--do-not-destroy

变成:

def main(do_not_destroy):

测试代码:

@click.command()
@click.option('--opt-with-dashes')
def hello(opt_with_dashes):
    """A Simple program"""
    click.echo('Opt w/ Dashes: {}'.format(opt_with_dashes))


if __name__ == '__main__':
    hello('--opt-with-dashes OPTION'.split())

结果:

Opt w/ Dashes: OPTION