Skip to content

auto_envvar_prefix does not work with command groups #501

@BlinkyStitt

Description

@BlinkyStitt

I made this example program:

import click


@click.group()
@click.option('--debug/--no-debug')
def cli(debug):
    click.echo('Debug mode is %s' % ('on' if debug else 'off'))


@cli.command()
@click.option('--username')
def greet(username):
    click.echo('Hello %s!' % username)


if __name__ == '__main__':
    cli(auto_envvar_prefix='GREETER')

auto_envvar_prefix only works for GREETER_DEBUG. Setting GREETER_USERNAME has no effect

Expected result:

$ export GREETER_DEBUG="false"
$ export GREETER_USERNAME="John"
$ python greet.py greet
Debug mode is off
Hello John!

Actual result:

$ export GREETER_DEBUG="false"
$ export GREETER_USERNAME="John"
$ python greet.py greet
Debug mode is off
Hello None!

For now, I am setting envvar on my options, but there are a lot of them

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions