私はclick
libを使用しています。私のコードでどの機能を呼び出すことができますか?印刷ヘルプメッセージ
、時々私は、ヘルプMSGを印刷したい しかし、私が知っている唯一の方法は次のとおりです。
python xxx --help
しかし、私は特定の機能を使用して私のコードのヘルプMSG を印刷したいです、例:
click.print_help_msg()
このような機能はありますか?
私はclick
libを使用しています。私のコードでどの機能を呼び出すことができますか?印刷ヘルプメッセージ
、時々私は、ヘルプMSGを印刷したい しかし、私が知っている唯一の方法は次のとおりです。
python xxx --help
しかし、私は特定の機能を使用して私のコードのヘルプMSG を印刷したいです、例:
click.print_help_msg()
このような機能はありますか?
あなたは、私がclick.echoの出力は「パイソンXXX --help」の出力と同じようにしたいコマンドのget_help方法
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)
クリックのドキュメントのサンプルを修正してこれを思いついた、私はこれまでにそれを使用していない、または以下のコードをテストしました。
@click.command()
@click.option('--help')
def help():
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo(get_help_message())
def get_help_message():
return "I AM A HELP MESSAGE!"
このようなものは動作しませんか?以下のようなタイプに基づいても、カラーコードとフィルタリングをサポートしています
click.echo('FooBar')
echo
:
を使用することができ、任意の解決策はありますか? – user3978288
あなたはこのようclick.echo
なものを使用することができます
click.echo('FooBar', err=True)
をあなたがより理解するためにdocumentationを参照することができます。
私はclick.echoの出力を "python xxx --help"の出力と同じにしたいのですが、解決策はありますか? – user3978288
これは私が一番欲しいものです!あなたの素敵な答えをありがとう – user3978288