diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-16 22:40:30 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-16 22:40:30 -0400 |
commit | 7e374ac3133b3547961e449bec1726178fc785d7 (patch) | |
tree | 372ef09cc0c370f3fe3bc2f9637055edf5e6d75c /cmd2/cmd2.py | |
parent | 7a3a84cc99322ee349167861f5a03937ade88f24 (diff) | |
download | cmd2-git-7e374ac3133b3547961e449bec1726178fc785d7.tar.gz |
Added documentation for ns_provider
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 7c868c3d..f5a2a844 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -192,15 +192,16 @@ def with_argument_list(*args: List[Callable], preserve_quotes: bool = False) -> def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, *, - ns_provider: Optional[Callable[[None], argparse.Namespace]] = None, + ns_provider: Optional[Callable[..., 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 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 ns_provider: An optional function that accepts a cmd2.Cmd object as an argument and returns an + argparse.Namespace. This is useful if the Namespace needs to be prepopulated with + state data that affects parsing. :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 @@ -251,14 +252,15 @@ def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, *, def with_argparser(argparser: argparse.ArgumentParser, *, - ns_provider: Optional[Callable[[None], argparse.Namespace]] = None, + ns_provider: Optional[Callable[..., 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 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 ns_provider: An optional function that accepts a cmd2.Cmd object as an argument and returns an + argparse.Namespace. This is useful if the Namespace needs to be prepopulated with + state data that affects parsing. :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 |