Environment variable name generation from command name is broken
See original GitHub issueWhen command names contain a -
character, automatic environment variable name generation is broken
#!/usr/bin/env python3
import click
@click.group()
@click.option('--debug/--no-debug')
def cli(debug):
click.echo('Debug mode is %s' % ('on' if debug else 'off'))
@click.command(name="greet-me")
@click.option('--username', show_envvar=True)
def greet(username):
click.echo('Hello %s!' % username)
if __name__ == '__main__':
cli.add_command(greet)
cli(auto_envvar_prefix='GREETER')
$ pipenv run python ./test.py greet-me --help
Loading .env environment variables…
Debug mode is off
Usage: test.py greet-me [OPTIONS]
Options:
--username TEXT [env var: GREETER_GREET-ME_USERNAME]
--help Show this message and exit.
This seems to be solved by changing core.py:329
to
# If there is no envvar prefix yet, but the parent has one and
# the command on this level has a name, we can expand the envvar
# prefix automatically.
if auto_envvar_prefix is None:
if parent is not None \
and parent.auto_envvar_prefix is not None and \
self.info_name is not None:
auto_envvar_prefix = '%s_%s' % (parent.auto_envvar_prefix,
self.info_name.upper().replace("-", "_"))
I’m not opening a pull request though as I’m not familiar with click
’s codebase and
- I’m not sure the modification above is general enough as there are other instances of
<something>.name.upper()
found incore.py
- I’m not sure replacing
-
with_
covers all the tricky cases
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Renaming environment variables by changing variable name ...
The loop uses "${!proj_env_repo@}" to generate a list of variable names that share the name prefix proj_env_repo .
Read more >Shell command "find -name $variable" not working as expected
What I am trying to do is grab the second field for every line in the file. txt file, pipe it to the...
Read more >How to generate environment variable name dynamically and ...
I want to generate environment variable name dynamically and set the value to that variable. I wrote a shell script as below. In...
Read more >How to fix a "Command not found" error in Linux - Red Hat
The env command prints out all global environment variables. ... distributions use uppercase for environment variable names by default.
Read more >Environment variables - ArchWiki
An environment variable is a named object that contains data used by one or more applications. In simple terms, it is a variable...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue is causing me problems as well. Thank you @gpakosz for submitting a fix!
@davidism can this be added to the next milestone by chance?