Skip to content

Method for setting auto_envvar_prefix as part of CLI declaration? #2684

Answered by mbra
rsyring asked this question in Q&A
Discussion options

You must be logged in to vote

I came across this discussion while I was looking for a solution that does not require me to pass auto_envvar_prefix multiple times and instead rely on the top-level group/command provide the information for click to interpret later. Which was my understand of "as part of CLI declaration" as opposed to the "imperative" way of wrapping the top-level callable and passing the prefix.

I found the context_settings argument to help with this

import click
import click.testing


@click.group(context_settings={"auto_envvar_prefix": "GREETER"})
def cli():
    pass


@cli.group()
def say():
    pass

@say.command()
@click.option("--who")
def hello(who):
    print(f"Hello {who}!")


def test_greeter(…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rsyring
Comment options

@mbra
Comment options

Answer selected by rsyring
@jbf81tb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants