diff options
author | kotfu <kotfu@kotfu.net> | 2018-01-12 23:11:53 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-01-12 23:11:53 -0700 |
commit | 405f4e4e951e0af46c7c5d746459f24e5c316eab (patch) | |
tree | 7933766506292f7610d5b05aa5f6615b32e2bff7 /cmd2.py | |
parent | c26b00853633c7df8cdee0ee49b3596154bb09c1 (diff) | |
download | cmd2-git-405f4e4e951e0af46c7c5d746459f24e5c316eab.tar.gz |
add use_argument_list setting
new attribute on Cmd2.cmd which defaults to false, but if set true, causes all do_* commands to receive a list of arguments, instead of a string of what the user typed.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -518,6 +518,7 @@ class Cmd(cmd.Cmd): excludeFromHistory = '''run ru r history histor histo hist his hi h edit edi ed e eof eo eos'''.split() exclude_from_help = ['do_eof', 'do_eos'] # Commands to exclude from the help menu reserved_words = [] + use_argument_list = False # Attributes which ARE dynamically settable at runtime abbrev = False # Abbreviated commands recognized @@ -1025,7 +1026,18 @@ class Cmd(cmd.Cmd): func = getattr(self, funcname) except AttributeError: return self.default(statement) - stop = func(statement) + + if self.use_argument_list: + lexed_arglist = shlex.split(statement, posix=POSIX_SHLEX) + # If not using POSIX shlex, make sure to strip off outer quotes for convenience + if not POSIX_SHLEX and STRIP_QUOTES_FOR_NON_POSIX: + temp_arglist = [] + for arg in lexed_arglist: + temp_arglist.append(strip_quotes(arg)) + lexed_arglist = temp_arglist + stop = func(lexed_arglist) + else: + stop = func(statement) return stop def default(self, statement): |