Skip to content

Commit 6439aae

Browse files
committed
flag to control Windows pattern expansion
1 parent fcf8205 commit 6439aae

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Unreleased
2727
needed. :issue:`1895`
2828
- If a default value is invalid, it does not prevent showing help
2929
text. :issue:`1889`
30+
- Pass ``windows_expand_args=False`` when calling the main command to
31+
disable pattern expansion on Windows. There is no way to escape
32+
patterns in CMD, so if the program needs to pass them on as-is then
33+
expansion must be disabled. :issue:`1901`
3034

3135

3236
Version 8.0.0

src/click/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ def main(
993993
prog_name: t.Optional[str] = None,
994994
complete_var: t.Optional[str] = None,
995995
standalone_mode: bool = True,
996+
windows_expand_args: bool = True,
996997
**extra: t.Any,
997998
) -> t.Any:
998999
"""This is the way to invoke a script with all the bells and
@@ -1021,9 +1022,15 @@ def main(
10211022
propagated to the caller and the return
10221023
value of this function is the return value
10231024
of :meth:`invoke`.
1025+
:param windows_expand_args: Expand glob patterns, user dir, and
1026+
env vars in command line args on Windows.
10241027
:param extra: extra keyword arguments are forwarded to the context
10251028
constructor. See :class:`Context` for more information.
10261029
1030+
.. versionchanged:: 8.0.1
1031+
Added the ``windows_expand_args`` parameter to allow
1032+
disabling command line arg expansion on Windows.
1033+
10271034
.. versionchanged:: 8.0
10281035
When taking arguments from ``sys.argv`` on Windows, glob
10291036
patterns, user dir, and env vars are expanded.
@@ -1038,7 +1045,7 @@ def main(
10381045
if args is None:
10391046
args = sys.argv[1:]
10401047

1041-
if os.name == "nt":
1048+
if os.name == "nt" and windows_expand_args:
10421049
args = _expand_args(args)
10431050
else:
10441051
args = list(args)

0 commit comments

Comments
 (0)