From 6439aaedbd886d2db6095e7677c7920b86839a88 Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 19 May 2021 13:50:30 -0700 Subject: [PATCH] flag to control Windows pattern expansion --- CHANGES.rst | 4 ++++ src/click/core.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9bc6e54af..a0a6e2bac 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/src/click/core.py b/src/click/core.py index 7000cffc1..e2ccf59a3 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -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 @@ -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. @@ -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)