~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-20 13:34:07 UTC
  • mto: (5622.4.1 uninstall-hook)
  • mto: This revision was merged to the branch mainline in revision 5747.
  • Revision ID: jelmer@samba.org-20110220133407-zhgrvuhhc1e3j2fn
Add more lazily usable hook points.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    )
47
47
""")
48
48
 
49
 
from bzrlib.hooks import HookPoint, Hooks
 
49
from bzrlib.hooks import Hooks
50
50
# Compatibility - Option used to be in commands.
51
51
from bzrlib.option import Option
52
52
from bzrlib.plugin import disable_plugins, load_plugins
769
769
class CommandHooks(Hooks):
770
770
    """Hooks related to Command object creation/enumeration."""
771
771
 
772
 
    def __init__(self):
 
772
    def __init__(self, module_name, member_name):
773
773
        """Create the default hooks.
774
774
 
775
775
        These are all empty initially, because by default nothing should get
776
776
        notified.
777
777
        """
778
 
        Hooks.__init__(self)
779
 
        self.create_hook(HookPoint('extend_command',
 
778
        Hooks.__init__(self, module_name, member_name)
 
779
        self.add_hook('extend_command',
780
780
            "Called after creating a command object to allow modifications "
781
781
            "such as adding or removing options, docs etc. Called with the "
782
 
            "new bzrlib.commands.Command object.", (1, 13), None))
783
 
        self.create_hook(HookPoint('get_command',
 
782
            "new bzrlib.commands.Command object.", (1, 13))
 
783
        self.add_hook('get_command',
784
784
            "Called when creating a single command. Called with "
785
785
            "(cmd_or_None, command_name). get_command should either return "
786
786
            "the cmd_or_None parameter, or a replacement Command object that "
787
787
            "should be used for the command. Note that the Command.hooks "
788
788
            "hooks are core infrastructure. Many users will prefer to use "
789
789
            "bzrlib.commands.register_command or plugin_cmds.register_lazy.",
790
 
            (1, 17), None))
791
 
        self.create_hook(HookPoint('get_missing_command',
 
790
            (1, 17))
 
791
        self.add_hook('get_missing_command',
792
792
            "Called when creating a single command if no command could be "
793
793
            "found. Called with (command_name). get_missing_command should "
794
794
            "either return None, or a Command object to be used for the "
795
 
            "command.", (1, 17), None))
796
 
        self.create_hook(HookPoint('list_commands',
 
795
            "command.", (1, 17))
 
796
        self.add_hook('list_commands',
797
797
            "Called when enumerating commands. Called with a set of "
798
798
            "cmd_name strings for all the commands found so far. This set "
799
799
            " is safe to mutate - e.g. to remove a command. "
800
800
            "list_commands should return the updated set of command names.",
801
 
            (1, 17), None))
 
801
            (1, 17))
802
802
 
803
 
Command.hooks = CommandHooks()
 
803
Command.hooks = CommandHooks("bzrlib.commands", "Command.hooks")
804
804
 
805
805
 
806
806
def parse_args(command, argv, alias_argv=None):