Mercurial > python-cmd2
diff cmd2.py @ 245:2cda5a817e5a
send to ioug
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 25 Mar 2009 19:15:43 -0400 |
parents | e0c60ea7ad5d |
children | 2e37155d2b95 |
line wrap: on
line diff
--- a/cmd2.py Wed Mar 25 14:08:01 2009 -0400 +++ b/cmd2.py Wed Mar 25 19:15:43 2009 -0400 @@ -26,7 +26,7 @@ flagReader.py options are still supported for backward compatibility """ import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest -import unittest, string, datetime, urllib, inspect +import unittest, string, datetime, urllib, inspect, itertools from code import InteractiveConsole, InteractiveInterpreter, softspace from optparse import make_option __version__ = '0.5.0' @@ -265,8 +265,9 @@ abbrev = True nonpythoncommand = 'cmd' current_script_dir = None + reserved_words = [] settable = ['prompt', 'continuation_prompt', 'default_file_name', 'editor', - 'case_insensitive', 'echo', 'timing', 'abbrev'] + 'case_insensitive', 'echo', 'timing', 'abbrev'] settable.sort() editor = os.environ.get('EDITOR') @@ -306,6 +307,10 @@ self._init_parser() self.pystate = {} self.shortcuts = sorted(self.shortcuts.items(), reverse=True) + self.keywords = list(itertools.izip(self.reserved_words, itertools.repeat(None))) + \ + [(fname[3:], func) for (fname, func) in + inspect.getmembers(self, inspect.ismethod) + if fname.startswith('do_')] def do_shortcuts(self, args): """Lists single-key shortcuts available.""" @@ -625,8 +630,8 @@ except AttributeError: func = None if self.abbrev: # accept shortened versions of commands - funcs = [(fname, function) for (fname, function) in inspect.getmembers(self, inspect.ismethod) - if fname.startswith('do_' + statement.parsed.command)] + funcs = [(fname, function) for (fname, function) in self.keywords + if fname.startswith(statement.parsed.command)] if len(funcs) == 1: func = funcs[0][1] if not func: @@ -816,9 +821,9 @@ sys.stdin = self.stdin interp.interact(banner= "Python %s on %s\n%s\n(%s)\n%s" % (sys.version, sys.platform, cprt, self.__class__.__name__, self.do_py.__doc__)) - keepstate.restore() except EmbeddedConsoleExit: - return + pass + keepstate.restore() def do_history(self, arg): """history [arg]: lists past commands issued