diff options
-rwxr-xr-x | cmd2.py | 8 | ||||
-rw-r--r-- | docs/freefeatures.rst | 5 | ||||
-rwxr-xr-x | examples/paged_output.py | 3 | ||||
-rwxr-xr-x | examples/python_scripting.py | 6 |
4 files changed, 15 insertions, 7 deletions
@@ -44,7 +44,11 @@ import tempfile import traceback import unittest from code import InteractiveConsole -from enum import Enum + +try: + from enum34 import Enum +except ImportError: + from enum import Enum import pyparsing import pyperclip @@ -2137,7 +2141,7 @@ class Cmd(cmd.Cmd): if self.allow_appended_space and endidx == len(line): str_to_append += ' ' - self.completion_matches[0] = self.completion_matches[0] + str_to_append + self.completion_matches[0] += str_to_append try: return self.completion_matches[state] diff --git a/docs/freefeatures.rst b/docs/freefeatures.rst index d700d144..8255868c 100644 --- a/docs/freefeatures.rst +++ b/docs/freefeatures.rst @@ -345,3 +345,8 @@ which inherits from ``cmd2.Cmd``:: # Make sure you have an "import functools" somewhere at the top complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, dir_only=True) + + # Since Python 2 does not have functools.partialmethod(), you can achieve the + # same thing by implementing a tab completion function + def complete_bar(self, text, line, begidx, endidx): + return self.path_complete(text, line, begidx, endidx, dir_only=True) diff --git a/examples/paged_output.py b/examples/paged_output.py index 9005a4da..cb213087 100755 --- a/examples/paged_output.py +++ b/examples/paged_output.py @@ -2,7 +2,6 @@ # coding=utf-8 """A simple example demonstrating the using paged output via the ppaged() method. """ -import functools import cmd2 from cmd2 import with_argument_list @@ -25,7 +24,7 @@ class PagedOutput(cmd2.Cmd): text = f.read() self.ppaged(text) - complete_page_file = functools.partial(cmd2.path_complete) + complete_page_file = cmd2.Cmd.path_complete if __name__ == '__main__': diff --git a/examples/python_scripting.py b/examples/python_scripting.py index f4606251..5f7996e2 100755 --- a/examples/python_scripting.py +++ b/examples/python_scripting.py @@ -15,7 +15,6 @@ command and the "pyscript <script> [arguments]" syntax comes into play. This application and the "scripts/conditional.py" script serve as an example for one way in which this can be done. """ import argparse -import functools import os import cmd2 @@ -82,8 +81,9 @@ class CmdLineApp(cmd2.Cmd): self.perror(err, traceback_war=False) self._last_result = cmd2.CmdResult(out, err) - # Enable directory completion for cd command by freezing an argument to path_complete() with functools.partial - complete_cd = functools.partial(cmd2.path_complete, dir_only=True) + # Enable tab completion for cd command + def complete_cd(self, text, line, begidx, endidx): + return self.path_complete(text, line, begidx, endidx, dir_only=True) dir_parser = argparse.ArgumentParser() dir_parser.add_argument('-l', '--long', action='store_true', help="display in long format with one item per line") |