~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2008-11-05 00:21:17 UTC
  • mto: This revision was merged to the branch mainline in revision 678.
  • Revision ID: aaron@aaronbentley.com-20081105002117-ly7injhr5uacyl9s
More cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib import osutils
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.config import config_dir, ensure_config_dir_exists
30
 
from bzrlib.commands import get_cmd_object, all_command_names, get_alias
 
30
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
31
31
from bzrlib.errors import BzrError
32
32
from bzrlib.workingtree import WorkingTree
33
33
 
99
99
        self.identchars += '-'
100
100
        ensure_config_dir_exists()
101
101
        self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
102
 
        whitespace = ''.join(c for c in string.whitespace if c < chr(127))
103
 
        readline.set_completer_delims(whitespace)
 
102
        readline.set_completer_delims(string.whitespace)
104
103
        if os.access(self.history_file, os.R_OK) and \
105
104
            os.path.isfile(self.history_file):
106
105
            readline.read_history_file(self.history_file)
169
168
        self.default("help "+line)
170
169
 
171
170
    def default(self, line):
172
 
        try:
173
 
            args = shlex.split(line)
174
 
        except ValueError, e:
175
 
            print 'Parse error:', e
176
 
            return
177
 
 
 
171
        args = shlex.split(line)
178
172
        alias_args = get_alias(args[0])
179
173
        if alias_args is not None:
180
174
            args[0] = alias_args.pop(0)
192
186
            return os.system(line)
193
187
 
194
188
        try:
195
 
            is_qbzr = cmd_obj.__module__.startswith('bzrlib.plugins.qbzr.')
196
 
            if too_complicated(line) or is_qbzr:
 
189
            if too_complicated(line):
197
190
                return os.system("bzr "+line)
198
191
            else:
199
192
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
227
220
        return CompletionContext(text, command=cmd).get_completions()
228
221
 
229
222
 
230
 
def run_shell(directory=None):
 
223
def run_shell():
231
224
    try:
232
 
        if not directory is None:
233
 
            os.chdir(directory)
234
225
        prompt = PromptCmd()
235
 
        while True:
236
 
            try:
237
 
                try:
238
 
                    prompt.cmdloop()
239
 
                except KeyboardInterrupt:
240
 
                    print
241
 
            finally:
242
 
                prompt.write_history()
 
226
        try:
 
227
            prompt.cmdloop()
 
228
        finally:
 
229
            prompt.write_history()
243
230
    except StopIteration:
244
231
        pass
245
232
 
293
280
 
294
281
 
295
282
def iter_command_names(hidden=False):
296
 
    for real_cmd_name in all_command_names():
297
 
        cmd_obj = get_cmd_object(real_cmd_name)
298
 
        if not hidden and cmd_obj.hidden:
 
283
    for real_cmd_name, cmd_class in get_all_cmds():
 
284
        if not hidden and cmd_class.hidden:
299
285
            continue
300
 
        for name in [real_cmd_name] + cmd_obj.aliases:
 
286
        for name in [real_cmd_name] + cmd_class.aliases:
301
287
            # Don't complete on aliases that are prefixes of the canonical name
302
288
            if name == real_cmd_name or not real_cmd_name.startswith(name):
303
289
                yield name