diff options
author | cat <cat@eee> | 2010-02-12 16:28:15 -0500 |
---|---|---|
committer | cat <cat@eee> | 2010-02-12 16:28:15 -0500 |
commit | 64710504ae938f2cffdcea1ed1769a5b953921bc (patch) | |
tree | bac07dfdd7823aad059faccc57bdb9e1c2cb0950 /cmd2.py | |
parent | 6042e62e285f57a73d5db42d9c4b2a66a30d265a (diff) | |
download | cmd2-hg-64710504ae938f2cffdcea1ed1769a5b953921bc.tar.gz |
default_to_shell
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -393,6 +393,7 @@ class Cmd(cmd.Cmd): legalChars = '!#$%.:?@_' + pyparsing.alphanums + pyparsing.alphas8bit shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'} excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() + default_to_shell = True noSpecialParse = 'set ed edit exit'.split() defaultExtension = 'txt' # For ``save``, ``load``, etc. default_file_name = 'command.txt' # For ``save``, ``load``, etc. @@ -828,11 +829,11 @@ class Cmd(cmd.Cmd): self.lastcmd = statement.parsed.raw funcname = self.func_named(statement.parsed.command) if not funcname: - return self.postparsing_postcmd(self.default(statement.full_parsed_statement())) + return self._default(statement) try: func = getattr(self, funcname) except AttributeError: - return self.postparsing_postcmd(self.default(statement.full_parsed_statement())) + return self._default(statement) timestart = datetime.datetime.now() stop = func(statement) if self.timing: @@ -855,6 +856,14 @@ class Cmd(cmd.Cmd): return self.postparsing_postcmd(stop) + def _default(self, statement): + arg = statement.full_parsed_statement() + if self.default_to_shell: + result = os.system(arg) + if not result: + return self.postparsing_postcmd(None) + return self.postparsing_postcmd(self.default(arg)) + def pseudo_raw_input(self, prompt): """copied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdout""" |