Search code examples
pythonenvironment-variablespython-click

Get Click to not expand variables in argument


I have a simple Click app like this:

import click

@click.command()
@click.argument('message')
def main(message: str):
    click.echo(message)

if __name__ == '__main__':
    main()

When you pass an environment variable in the argument, it expands it:

➜  Desktop python foo.py '$M0/.viola/2025-01-25-17-20-23-307878'
M:/home/ramrachum/.viola/2025-01-25-17-20-23-307878

Note that I used single quotes above, so my shell is not expanding the environment variable, Click does. How do I get Click to not expand it?


Solution

  • The solution is to pass windows_expand_args=False when calling the main command.