Skip to content

Conversation

@alkasm
Copy link
Contributor

@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.

@ofek ofek force-pushed the alkasm/keep-context-settings branch from 63b9ff2 to 55c75ad Compare April 7, 2025 14:58
Copy link
Collaborator

@ofek ofek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ofek ofek merged commit 0ba4d85 into mkdocs:master Apr 7, 2025
9 checks passed
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.

2 participants