单击lib是否提供一种打印内置帮助消息的方法? [英] Does click lib provide a way to print the builtin help message?
本文介绍了单击lib是否提供一种打印内置帮助消息的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用click
lib.
在我的代码中,有时我想打印帮助msg, 但是我知道的唯一方法是:
In my code , sometimes I want to print help msg , But the only way I know is :
python xxx --help
但是我想使用某些功能在代码中打印帮助消息 ,例如:
But I want to print the help msg in my code using a certain function , for example:
click.print_help_msg()
有这样的功能吗?
推荐答案
You can use Command's get_help method
import click
@click.command()
@click.option('--name', help='The person to greet.')
def hello(name):
"""Simple program that greets NAME."""
click.echo('Hello %s!' % name)
def print_help_msg(command):
with click.Context(command) as ctx:
click.echo(command.get_help(ctx))
>> print_help_msg(hello)
这篇关于单击lib是否提供一种打印内置帮助消息的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文