Skip to content

Commit 554561b

Browse files
committed
Addressed code review comments
1 parent 88ce0b5 commit 554561b

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

cmd2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
import traceback
4545
import unittest
4646
from code import InteractiveConsole
47-
from enum import Enum
47+
48+
try:
49+
from enum34 import Enum
50+
except ImportError:
51+
from enum import Enum
4852

4953
import pyparsing
5054
import pyperclip
@@ -2137,7 +2141,7 @@ def complete(self, text, state):
21372141
if self.allow_appended_space and endidx == len(line):
21382142
str_to_append += ' '
21392143

2140-
self.completion_matches[0] = self.completion_matches[0] + str_to_append
2144+
self.completion_matches[0] += str_to_append
21412145

21422146
try:
21432147
return self.completion_matches[state]

docs/freefeatures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,8 @@ which inherits from ``cmd2.Cmd``::
345345

346346
# Make sure you have an "import functools" somewhere at the top
347347
complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, dir_only=True)
348+
349+
# Since Python 2 does not have functools.partialmethod(), you can achieve the
350+
# same thing by implementing a tab completion function
351+
def complete_bar(self, text, line, begidx, endidx):
352+
return self.path_complete(text, line, begidx, endidx, dir_only=True)

examples/paged_output.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# coding=utf-8
33
"""A simple example demonstrating the using paged output via the ppaged() method.
44
"""
5-
import functools
65

76
import cmd2
87
from cmd2 import with_argument_list
@@ -25,7 +24,7 @@ def do_page_file(self, args):
2524
text = f.read()
2625
self.ppaged(text)
2726

28-
complete_page_file = functools.partial(cmd2.path_complete)
27+
complete_page_file = cmd2.Cmd.path_complete
2928

3029

3130
if __name__ == '__main__':

examples/python_scripting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
This application and the "scripts/conditional.py" script serve as an example for one way in which this can be done.
1616
"""
1717
import argparse
18-
import functools
1918
import os
2019

2120
import cmd2
@@ -82,8 +81,9 @@ def do_cd(self, arglist):
8281
self.perror(err, traceback_war=False)
8382
self._last_result = cmd2.CmdResult(out, err)
8483

85-
# Enable directory completion for cd command by freezing an argument to path_complete() with functools.partial
86-
complete_cd = functools.partial(cmd2.path_complete, dir_only=True)
84+
# Enable tab completion for cd command
85+
def complete_cd(self, text, line, begidx, endidx):
86+
return self.path_complete(text, line, begidx, endidx, dir_only=True)
8787

8888
dir_parser = argparse.ArgumentParser()
8989
dir_parser.add_argument('-l', '--long', action='store_true', help="display in long format with one item per line")

0 commit comments

Comments
 (0)