Consider the following minimal Click script mytool.py:
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)
if __name__ == '__main__':
hello()
How can I access the Context object Click generates for this script when I call it with
python mytool.py
In particular access to the the info_name attribute is important (so that, when I programmatically want to display the help message, the script name mytool.py is populated.(*)
(*) I know that I can generate a new Context object via click.Context(hello) but this context does not contain by itself the info_name property. Of course I can figure out the script name manually, but Click certainly creates a default context with the script name and I believe that one would be the best to access. (See also Does click lib provide a way to print the builtin help message?)