/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2009-02-11 12:49:50 UTC
  • mto: (4000.2.2 test-result-registry)
  • mto: This revision was merged to the branch mainline in revision 4003.
  • Revision ID: robertc@robertcollins.net-20090211124950-70c4aa2a8ub65d0s
Add a new hook Commands['extend_command'] for plugins that want to alter commands without overriding the entire command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
from bzrlib import registry
52
52
# Compatibility
 
53
from bzrlib.hooks import Hooks
53
54
from bzrlib.option import Option
54
55
 
55
56
 
170
171
        If true, plugin commands can override builtins.
171
172
    """
172
173
    try:
173
 
        return _get_cmd_object(cmd_name, plugins_override)
 
174
        cmd = _get_cmd_object(cmd_name, plugins_override)
 
175
        # Allow plugins to extend commands
 
176
        for hook in Command.hooks['extend_command']:
 
177
            hook(cmd)
 
178
        return cmd
174
179
    except KeyError:
175
180
        raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
176
181
 
216
221
        except errors.NoPluginAvailable:
217
222
            pass
218
223
        else:
219
 
            raise errors.CommandAvailableInPlugin(cmd_name, 
 
224
            raise errors.CommandAvailableInPlugin(cmd_name,
220
225
                                                  plugin_metadata, provider)
221
 
 
222
226
    raise KeyError
223
227
 
224
228
 
279
283
            sys.stdout is forced to be a binary stream, and line-endings
280
284
            will not mangled.
281
285
 
 
286
    :cvar hooks: An instance of CommandHooks.
282
287
    """
283
288
    aliases = []
284
289
    takes_args = []
573
578
            return None
574
579
 
575
580
 
 
581
class CommandHooks(Hooks):
 
582
    """Hooks related to Command object creation/enumeration."""
 
583
 
 
584
    def __init__(self):
 
585
        """Create the default hooks.
 
586
 
 
587
        These are all empty initially, because by default nothing should get
 
588
        notified.
 
589
        """
 
590
        Hooks.__init__(self)
 
591
        # Introduced in 0.13:
 
592
        # invoked after creating a command object to allow modifications such
 
593
        # as adding or removing options, docs etc. Invoked with the command
 
594
        # object.
 
595
        self['extend_command'] = []
 
596
 
 
597
Command.hooks = CommandHooks()
 
598
 
 
599
 
576
600
def parse_args(command, argv, alias_argv=None):
577
601
    """Parse command line.
578
602
    
846
870
        # --verbose in their own way.
847
871
        option._verbosity_level = saved_verbosity_level
848
872
 
 
873
 
849
874
def display_command(func):
850
875
    """Decorator that suppresses pipe/interrupt errors."""
851
876
    def ignore_pipe(*args, **kwargs):