click_config_file icon indicating copy to clipboard operation
click_config_file copied to clipboard

Invoking click tool with --help changes default display results

Open brutog opened this issue 2 years ago • 3 comments

When using the option to show defaults in help text:

@click.group(context_settings=dict(show_default=True))

I see a bad behavior. When the tool is invoked with --help, it has the wrong path for the config file:

$ toolname --help
Usage: jast [OPTIONS] COMMAND [ARGS]...

Options:
  --config FILE  Read configuration from FILE.  [default:
                 /home/user/.config/toolname/config]
  --help         Show this message and exit.  [default: False]

Commands:
  command1
  command2
  command3

If the tool is invoked without --help, or any command at all, such that the help is forced to display, I see the right default for the configuration file:

$ toolname
Usage: jast [OPTIONS] COMMAND [ARGS]...

Options:
  --config FILE  Read configuration from FILE.  [default:
                 /home/user/.toolnamerc]
  --help         Show this message and exit.  [default: False]

Commands:
  command1
  command2
  command3

This could be confusing for users.

brutog avatar May 20 '22 03:05 brutog

Could you please provide a minimal example to reproduce this?

phha avatar May 20 '22 06:05 phha

Sure. This should reproduce:

import click
import click_config_file


@click.group(context_settings=dict(show_default=True))
@click.pass_context
@click_config_file.configuration_option(default='/tmp/.configfile')
def cli(ctx):
    pass

brutog avatar May 20 '22 06:05 brutog

I'll look into this. For now you can fix it by passing @click_config_file.configuration_option(default='/tmp/.configfile', implicit=False)

phha avatar May 20 '22 08:05 phha