Skip to content

Commit

Permalink
Merge pull request #1918 from pallets/disable-windows-expansion
Browse files Browse the repository at this point in the history
flag to control Windows pattern expansion
  • Loading branch information
davidism authored May 19, 2021
2 parents fcf8205 + 6439aae commit 6e91b13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Unreleased
needed. :issue:`1895`
- If a default value is invalid, it does not prevent showing help
text. :issue:`1889`
- Pass ``windows_expand_args=False`` when calling the main command to
disable pattern expansion on Windows. There is no way to escape
patterns in CMD, so if the program needs to pass them on as-is then
expansion must be disabled. :issue:`1901`


Version 8.0.0
Expand Down
9 changes: 8 additions & 1 deletion src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ def main(
prog_name: t.Optional[str] = None,
complete_var: t.Optional[str] = None,
standalone_mode: bool = True,
windows_expand_args: bool = True,
**extra: t.Any,
) -> t.Any:
"""This is the way to invoke a script with all the bells and
Expand Down Expand Up @@ -1021,9 +1022,15 @@ def main(
propagated to the caller and the return
value of this function is the return value
of :meth:`invoke`.
:param windows_expand_args: Expand glob patterns, user dir, and
env vars in command line args on Windows.
:param extra: extra keyword arguments are forwarded to the context
constructor. See :class:`Context` for more information.
.. versionchanged:: 8.0.1
Added the ``windows_expand_args`` parameter to allow
disabling command line arg expansion on Windows.
.. versionchanged:: 8.0
When taking arguments from ``sys.argv`` on Windows, glob
patterns, user dir, and env vars are expanded.
Expand All @@ -1038,7 +1045,7 @@ def main(
if args is None:
args = sys.argv[1:]

if os.name == "nt":
if os.name == "nt" and windows_expand_args:
args = _expand_args(args)
else:
args = list(args)
Expand Down

0 comments on commit 6e91b13

Please sign in to comment.