一种更改单击的方法默认帮助选项?
每当您使用单击创建命令或组时,都会有一个默认- help
选项以携带用法指南:
import click
@click.command()
def main():
click.echo('Success!')
if __name__ == '__main__':
main()
如果我使用- help help
运行文件,我应该get:
$ python file.py --help
Usage: file.py [OPTIONS]
Options:
--help Show this message and exit.
现在,单击允许您通过装饰器中的参数通过终端调用help> help
选项的覆盖方式:
@click.command(
context_settings=dict(
help_option_names=['-f', '--foo']
)
)
def main():
click.echo('Success!')
$ python file.py -f
Usage: file.py [OPTIONS]
Options:
-f, --foo Show this message and exit.
但是,通过click
是否有一个参数可以指定到click.command
覆盖文本“显示此消息并退出” 在终端寻求帮助时?
Whenever you create a command or group with Click, there's a default --help
option to bring the usage guide:
import click
@click.command()
def main():
click.echo('Success!')
if __name__ == '__main__':
main()
If I run the file with the --help
, I should get:
$ python file.py --help
Usage: file.py [OPTIONS]
Options:
--help Show this message and exit.
Now, Click allows you to override how the help
option is called through the terminal via a parameter in the decorator:
@click.command(
context_settings=dict(
help_option_names=['-f', '--foo']
)
)
def main():
click.echo('Success!')
$ python file.py -f
Usage: file.py [OPTIONS]
Options:
-f, --foo Show this message and exit.
However, rummaging through Click's documentation, I don't see a similar option to override the default help message.
Is there a parameter to specify to click.command
that overrides the text "Show this message and exit" when calling for help in the terminal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了更改帮助文本,仅单行 装饰器已经足够了
,您可以按照完整的 @stephen Rauch 的详细调整,
For changing help text only a one-line
help_option
decorator is sufficientAlternatively you can follow the full @Stephen Rauch's answer to tweak it in details
您可以使用
help_option 装饰器
示例代码:
测试代码:
测试结果:
You can change click's default help option with the
help_option
decoratorSample Code:
Test Code:
Test Results: