diff options
author | Catherine Devlin <catherine.devlin@gsa.gov> | 2017-05-29 21:09:24 -0500 |
---|---|---|
committer | Catherine Devlin <catherine.devlin@gsa.gov> | 2017-05-29 21:09:24 -0500 |
commit | 6c759f1e3851c2df45d7a47f975baf23fc7d320c (patch) | |
tree | 297b91b621224ac49ef17a5459cefdc659af2767 /cmd2.py | |
parent | da5cc1cb9f54720cc03647ebf703e2b0bd42d872 (diff) | |
parent | d86ea01b5ade92139021447f5fd135f392b45c9a (diff) | |
download | cmd2-git-6c759f1e3851c2df45d7a47f975baf23fc7d320c.tar.gz |
Merge branch 'remove_parseline' into extract_parser_methods
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 34 |
1 files changed, 4 insertions, 30 deletions
@@ -87,7 +87,7 @@ try: except ImportError: pass -__version__ = '0.7.2' +__version__ = '0.7.3a' # Pyparsing enablePackrat() can greatly speed up parsing, but problems have been seen in Python 3 in the past pyparsing.ParserElement.enablePackrat() @@ -548,7 +548,8 @@ def replace_with_file_contents(fname): """ if fname: try: - result = open(os.path.expanduser(fname[0])).read() + with open(os.path.expanduser(fname[0])) as source_file: + result = source_file.read() except IOError: result = '< %s' % fname[0] # wasn't a file after all else: @@ -821,33 +822,6 @@ class Cmd(cmd.Cmd): """ return stop - def parseline(self, line): - """Parse the line into a command name and a string containing the arguments. - - Used for command tab completion. Returns a tuple containing (command, args, line). - 'command' and 'args' may be None if the line couldn't be parsed. - - :param line: str - line read by readline - :return: (str, str, str) - tuple containing (command, args, line) - """ - line = line.strip() - - if not line: - # Deal with empty line or all whitespace line - return None, None, line - - # Expand command shortcuts to the full command name - for (shortcut, expansion) in self.shortcuts: - if line.startswith(shortcut): - line = line.replace(shortcut, expansion + ' ', 1) - break - - i, n = 0, len(line) - while i < n and line[i] in self.identchars: - i += 1 - command, arg = line[:i], line[i:].strip() - return command, arg, line - def onecmd_plus_hooks(self, line): """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks. @@ -1439,7 +1413,7 @@ class Cmd(cmd.Cmd): if len(possible_path) == 0 and not text: return [] - if os.path.sep not in possible_path: + if os.path.sep not in possible_path and possible_path != '~': # The text before the search text is not a directory path. # It is OK to try shell command completion. command_completions = self._shell_command_complete(text) |