-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Environment variable name generation from command name is broken #1253
Comments
In fact, it also happens when not setting the command name explicitly but letting
|
This issue is causing me problems as well. Thank you @gpakosz for submitting a fix! |
I guess it's related to 5d1df0e |
@davidism can this be added to the next milestone by chance? |
Stumbled over this today as well. Maybe Command Aliases might be a workaround until #1261 is merged? |
Unfortunately, Command Aliases can not be used as a workaround here (at least not how I am doing it): import click
# this Group allows specifying both "greet_me" and "greet-me"
# (https://click.palletsprojects.com/en/7.x/advanced/?highlight=alias#command-aliases)
class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [
x
for x in self.list_commands(ctx)
if x in (cmd_name, cmd_name.replace("-", "_"))
]
if not matches:
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])
@click.group(
cls=AliasedGroup,
# setting the auto_envvar_prefix here works better with
# setuptools/console_scripts
context_settings={"auto_envvar_prefix": "GREETER"},
)
def cli():
click.echo("click version {}".format(click.__version__))
@cli.command(name="greet_me") # force the name to include the underscore
@click.option("--username", show_envvar=True)
def greet_me(username):
click.echo("Hello %s!" % username)
if __name__ == "__main__":
cli() This can be invoked both with python3 -m test greet_me --help
click version 7.0
Usage: test.py greet_me [OPTIONS]
Options:
--username TEXT [env var: GREETER_GREET_ME_USERNAME]
--help Show this message and exit. python3 -m test greet-me --help
click version 7.0
Usage: test.py greet-me [OPTIONS]
Options:
--username TEXT [env var: GREETER_GREET-ME_USERNAME]
--help Show this message and exit.
|
Prevent environment variables from containing '-' characters
When command names contain a
-
character, automatic environment variable name generation is brokenThis seems to be solved by changing
core.py:329
toI'm not opening a pull request though as I'm not familiar with
click
's codebase and<something>.name.upper()
found incore.py
-
with_
covers all the tricky casesThe text was updated successfully, but these errors were encountered: