~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

[merge] robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
import bzrlib
37
37
import bzrlib.trace
38
38
from bzrlib.trace import mutter, note, log_error, warning
39
 
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
 
39
from bzrlib.errors import (BzrError, 
 
40
                           BzrCheckError,
 
41
                           BzrCommandError,
 
42
                           BzrOptionError,
 
43
                           NotBranchError)
40
44
from bzrlib.revisionspec import RevisionSpec
41
45
from bzrlib import BZRDIR
42
46
from bzrlib.option import Option
44
48
plugin_cmds = {}
45
49
 
46
50
 
47
 
def register_command(cmd):
 
51
def register_command(cmd, decorate=False):
48
52
    "Utility function to help register a command"
49
53
    global plugin_cmds
50
54
    k = cmd.__name__
55
59
    if not plugin_cmds.has_key(k_unsquished):
56
60
        plugin_cmds[k_unsquished] = cmd
57
61
        mutter('registered plugin command %s', k_unsquished)      
 
62
        if decorate and k_unsquished in builtin_command_names():
 
63
            return _builtin_commands()[k_unsquished]
 
64
    elif decorate:
 
65
        result = plugin_cmds[k_unsquished]
 
66
        plugin_cmds[k_unsquished] = cmd
 
67
        return result
58
68
    else:
59
69
        log_error('Two plugins defined the same command: %r' % k)
60
70
        log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
213
223
        all_cmd_args.update(cmdopts)
214
224
 
215
225
        return self.run(**all_cmd_args)
216
 
 
217
226
    
218
227
    def run(self):
219
228
        """Actually run the command.
303
312
                else:
304
313
                    optname = a[2:]
305
314
                if optname not in cmd_options:
306
 
                    raise BzrCommandError('unknown long option %r for command %s' 
307
 
                            % (a, command.name()))
 
315
                    raise BzrOptionError('unknown long option %r for command %s'
 
316
                        % (a, command.name()))
308
317
            else:
309
318
                shortopt = a[1:]
310
319
                if shortopt in Option.SHORT_OPTIONS:
500
509
def display_command(func):
501
510
    def ignore_pipe(*args, **kwargs):
502
511
        try:
503
 
            func(*args, **kwargs)
 
512
            return func(*args, **kwargs)
504
513
        except IOError, e:
505
514
            if e.errno != errno.EPIPE:
506
515
                raise
507
516
        except KeyboardInterrupt:
508
 
            pass
 
517
            pass
509
518
    return ignore_pipe
510
519
 
511
520
def main(argv):