mkdocs-click
mkdocs-click copied to clipboard
pass command.context_settings to new context
When creating a context from the command, the context settings were not propagated, which means that some options set on the command would be ignored.
To illustrate:
import click
@click.command(context_settings={"help_option_names": ["-h", "--help"], "show_default": True})
@click.option("-t", "--test", type=int, default=42)
def cli(test):
print("the number is", test)
Now compare ctx.get_help() when the context is and is not passed through:
>>> ctx = click.Context(cli)
>>> print(ctx.get_help())
Usage: [OPTIONS]
Options:
-t, --test INTEGER
--help Show this message and exit.
>>> ctx = click.Context(cli, **cli.context_settings)
>>> print(ctx.get_help())
Usage: [OPTIONS]
Options:
-t, --test INTEGER [default: 42]
-h, --help Show this message and exit.
You'll see the additional -h short flag for help, and the default argument for -t which wasn't shown before.
With this fix, these settings are now respected through :style: plain so that the output matches what is shown at the command line after building with mkdocs.