Skip to content
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

Find a place to document windows console expansion setting #2851

Open
Rowlando13 opened this issue Jan 28, 2025 · 1 comment
Open

Find a place to document windows console expansion setting #2851

Rowlando13 opened this issue Jan 28, 2025 · 1 comment
Assignees
Labels
docs windows Issues pertaining to the Windows environment

Comments

@Rowlando13
Copy link
Collaborator

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.

@Rowlando13 Rowlando13 self-assigned this Jan 28, 2025
@Rowlando13 Rowlando13 added docs windows Issues pertaining to the Windows environment labels Jan 28, 2025
@Rowlando13
Copy link
Collaborator Author

Not sure where to put this. It is already documented in the api section under the Command->main, but it is probably a common question and the api docs are large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs windows Issues pertaining to the Windows environment
Projects
None yet
Development

No branches or pull requests

1 participant