summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-12 23:11:53 -0700
committerkotfu <kotfu@kotfu.net>2018-01-12 23:11:53 -0700
commit405f4e4e951e0af46c7c5d746459f24e5c316eab (patch)
tree7933766506292f7610d5b05aa5f6615b32e2bff7 /cmd2.py
parentc26b00853633c7df8cdee0ee49b3596154bb09c1 (diff)
downloadcmd2-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-xcmd2.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index fe6213a8..0fc6c32c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -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):