Call which function can help message help

I am using clicklib.

In my code sometimes I want to print out the help help, But the only way I know is:

python xxx --help

But I want to print msg help in my code using a specific function for exmaple:

click.print_help_msg()

Is there such a function?

+4
source share
3 answers

You can use get_help method command

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)
+6
source

I changed the sample in the click documentation and came up with this, I haven't used it before, or tested the code below.

@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!"

Maybe something like this doesn't work?

+1
source

click.echo - :

click.echo('FooBar')

echo , :

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

.

0

Source: https://habr.com/ru/post/1673710/


All Articles