Skip to content

Commit 0cea9be

Browse files
committed
Made ns_provider and preserve_quotes keyword-only args
1 parent fff34d2 commit 0cea9be

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cmd2/cmd2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ def cmd_wrapper(cmd2_instance, statement: Union[Statement, str]):
191191
return arg_decorator
192192

193193

194-
def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser,
195-
preserve_quotes: bool = False,
196-
ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,) -> \
194+
def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, *,
195+
ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,
196+
preserve_quotes: bool = False) -> \
197197
Callable[[argparse.Namespace, List], Optional[bool]]:
198198
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments with the given
199199
instance of argparse.ArgumentParser, but also returning unknown args as a list.
200200
201201
:param argparser: unique instance of ArgumentParser
202-
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
203202
:param ns_provider: an optional function that provides the Namespace for parse_known_args().
204203
this is useful if the Namespace needs to be prepopulated based on instance data.
204+
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
205205
:return: function that gets passed argparse-parsed args in a Namespace and a list of unknown argument strings
206206
A member called __statement__ is added to the Namespace to provide command functions access to the
207207
Statement object. This can be useful if the command function needs to know the command line.
@@ -250,17 +250,16 @@ def cmd_wrapper(cmd2_instance, statement: Union[Statement, str]):
250250
return arg_decorator
251251

252252

253-
def with_argparser(argparser: argparse.ArgumentParser,
254-
preserve_quotes: bool = False,
255-
ns_provider: Optional[Callable[[None], argparse.Namespace]] = None) -> \
256-
Callable[[argparse.Namespace], Optional[bool]]:
253+
def with_argparser(argparser: argparse.ArgumentParser, *,
254+
ns_provider: Optional[Callable[[None], argparse.Namespace]] = None,
255+
preserve_quotes: bool = False) -> Callable[[argparse.Namespace], Optional[bool]]:
257256
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments
258257
with the given instance of argparse.ArgumentParser.
259258
260259
:param argparser: unique instance of ArgumentParser
261-
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
262260
:param ns_provider: an optional function that provides the Namespace for parse_args().
263261
this is useful if the Namespace needs to be prepopulated based on instance data.
262+
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
264263
:return: function that gets passed the argparse-parsed args in a Namespace
265264
A member called __statement__ is added to the Namespace to provide command functions access to the
266265
Statement object. This can be useful if the command function needs to know the command line.

0 commit comments

Comments
 (0)