Skip to content

Find a place to document windows console expansion setting #2851

Open
@Rowlando13

Description

@Rowlando13

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docswindowsIssues pertaining to the Windows environment

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions