~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-18 00:16:41 UTC
  • mto: This revision was merged to the branch mainline in revision 767.
  • Revision ID: jelmer@samba.org-20101218001641-1ex046f0brdoeip5
Add DiffWriter.writelines.

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