2017-03-31 14 views

答えて

6

あなたは、私が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) 
+0

これは私が一番欲しいものです!あなたの素敵な答えをありがとう – user3978288

1

クリックのドキュメントのサンプルを修正してこれを思いついた、私はこれまでにそれを使用していない、または以下のコードをテストしました。

@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

+0

を使用することができ、任意の解決策はありますか? – user3978288

0

あなたはこのようclick.echoなものを使用することができます

click.echo('FooBar', err=True) 

をあなたがより理解するためにdocumentationを参照することができます。

+0

私はclick.echoの出力を "python xxx --help"の出力と同じにしたいのですが、解決策はありますか? – user3978288

関連する問題