Description
Document this:
Question
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?
Answer
If you don't want Click to emulate (as best it can) unix expansion on Windows, pass windows_expand_args=False when calling the CLI.
Windows command line doesn't do any *, ~, or $ENV expansion. It also doesn't distinguish between double quotes and single quotes (where the later means "don't expand here"`). Click emulates the expansion so that the app behaves similarly on both platforms, but doesn't receive information about what quotes were used. So you can disable it and do your own expansion (or not) if you have other needs.
Activity