@@ -175,25 +175,30 @@ def cat_decorator(func):
175175 return cat_decorator
176176
177177
178- def with_argument_list (func : Callable [[Statement ], Optional [bool ]],
179- preserve_quotes : bool = False ) -> Callable [[List ], Optional [bool ]]:
178+ def with_argument_list (* args : List [Callable ], preserve_quotes : bool = False ) -> Callable [[List ], Optional [bool ]]:
180179 """A decorator to alter the arguments passed to a do_* cmd2 method. Default passes a string of whatever the user
181180 typed. With this decorator, the decorated method will receive a list of arguments parsed from user input using
182181 shlex.split().
183182
184- :param func: do_* method this decorator is wrapping
183+ :param args: Single-element positional argument list containing do_* method this decorator is wrapping
185184 :param preserve_quotes: if True, then argument quotes will not be stripped
186185 :return: function that gets passed a list of argument strings
187186 """
188187 import functools
189188
190- @functools .wraps (func )
191- def cmd_wrapper (self , cmdline ):
192- lexed_arglist = parse_quoted_string (cmdline , preserve_quotes )
193- return func (self , lexed_arglist )
189+ def arg_decorator (func : Callable [[Statement ], Optional [bool ]]):
190+ @functools .wraps (func )
191+ def cmd_wrapper (self , cmdline ):
192+ lexed_arglist = parse_quoted_string (cmdline , preserve_quotes )
193+ return func (self , lexed_arglist )
194194
195- cmd_wrapper .__doc__ = func .__doc__
196- return cmd_wrapper
195+ cmd_wrapper .__doc__ = func .__doc__
196+ return cmd_wrapper
197+
198+ if len (args ) == 1 and callable (args [0 ]):
199+ return arg_decorator (args [0 ])
200+ else :
201+ return arg_decorator
197202
198203
199204def with_argparser_and_unknown_args (argparser : argparse .ArgumentParser , preserve_quotes : bool = False ) -> \
0 commit comments