Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass command.context_settings to new context #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alkasm
Copy link

@alkasm alkasm commented Sep 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant