diff options
-rw-r--r-- | cmd2/cmd2.py | 17 |
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. |