~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2005-10-27 05:19:16 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051027051916-0c47bc829ce54fdc
Got command completion working

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import readline
22
22
import string
23
23
from bzrlib.errors import BzrError
24
 
from bzrlib.commands import get_cmd_object
 
24
from bzrlib.commands import get_cmd_object, get_all_cmds
25
25
 
26
26
class PromptCmd(cmd.Cmd):
27
27
    def __init__(self):
127
127
 
128
128
    def completenames(self, text, line, begidx, endidx):
129
129
        completions = []
130
 
        iter = iter_command_names(self.fake_aba)
 
130
        iter = iter_command_names()
131
131
        try:
132
132
            if len(line) > 0:
133
133
                arg = line.split()[-1]
134
134
            else:
135
135
                arg = ""
136
 
            iter = cmdutil.iter_munged_completions(iter, arg, text)
 
136
            iter = list(iter_munged_completions(iter, arg, text))
137
137
        except Exception, e:
138
 
            print e
 
138
            print e, type(e)
139
139
        return list(iter)
140
140
 
141
141
    def completedefault(self, text, line, begidx, endidx):
232
232
    :type arg: str
233
233
    """
234
234
    return iter_file_completions(arg, True)
 
235
 
 
236
def iter_command_names(hidden=False):
 
237
    for real_cmd_name, cmd_class in get_all_cmds():
 
238
        if not hidden and cmd_class.hidden:
 
239
            continue
 
240
        for name in [real_cmd_name] + cmd_class.aliases:
 
241
            yield name
 
242
 
 
243
def iter_munged_completions(iter, arg, text):
 
244
    for completion in iter:
 
245
        completion = str(completion)
 
246
        if completion.startswith(arg):
 
247
            yield completion[len(arg)-len(text):]
 
248