summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-05-14 23:14:47 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-05-14 23:14:47 -0400
commit0cea9be6cc1630bd92f7a396f298c02d4f13450a (patch)
treef82bcb4cfbc65967725d48e3358696694945077e
parentfff34d20d37a4e8329dbaf10cfd0cb4e08621806 (diff)
downloadcmd2-git-0cea9be6cc1630bd92f7a396f298c02d4f13450a.tar.gz
Made ns_provider and preserve_quotes keyword-only args
-rw-r--r--cmd2/cmd2.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index c20205c7..7c868c3d 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -191,17 +191,17 @@ def with_argument_list(*args: List[Callable], preserve_quotes: bool = False) ->
return arg_decorator
-def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser,
- preserve_quotes: bool = False,
- ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,) -> \
+def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, *,
+ ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,
+ preserve_quotes: bool = False) -> \
Callable[[argparse.Namespace, List], Optional[bool]]:
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments with the given
instance of argparse.ArgumentParser, but also returning unknown args as a list.
:param argparser: unique instance of ArgumentParser
- :param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
:param ns_provider: an optional function that provides the Namespace for parse_known_args().
this is useful if the Namespace needs to be prepopulated based on instance data.
+ :param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
:return: function that gets passed argparse-parsed args in a Namespace and a list of unknown argument strings
A member called __statement__ is added to the Namespace to provide command functions access to the
Statement object. This can be useful if the command function needs to know the command line.
@@ -250,17 +250,16 @@ def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser,
return arg_decorator
-def with_argparser(argparser: argparse.ArgumentParser,
- preserve_quotes: bool = False,
- ns_provider: Optional[Callable[[None], argparse.Namespace]] = None) -> \
- Callable[[argparse.Namespace], Optional[bool]]:
+def with_argparser(argparser: argparse.ArgumentParser, *,
+ ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,
+ preserve_quotes: bool = False) -> Callable[[argparse.Namespace], Optional[bool]]:
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments
with the given instance of argparse.ArgumentParser.
:param argparser: unique instance of ArgumentParser
- :param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
:param ns_provider: an optional function that provides the Namespace for parse_args().
this is useful if the Namespace needs to be prepopulated based on instance data.
+ :param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
:return: function that gets passed the argparse-parsed args in a Namespace
A member called __statement__ is added to the Namespace to provide command functions access to the
Statement object. This can be useful if the command function needs to know the command line.