Exemple #1
0
 def test_register_command(self):
     """
     The L{CommandController.register_command} method adds a named
     C{bzrlib.commands.Command} to the controller.
     """
     self.controller.install_bzrlib_hooks()
     self.assertEquals(all_command_names(), set())
     self.controller.register_command("fake-command", FakeCommand)
     self.assertEquals(all_command_names(), set(["fake-command"]))
 def test_install_bzr_hooks(self):
     """
     L{CommandController.install_bzrlib_hooks} is called to hook the
     controller into C{bzrlib}.
     """
     main(["commandant", self.directory.path, "version"])
     self.assertEquals(all_command_names(), set(["help", "version"]))
Exemple #3
0
Fichier : run.py Projet : biji/qbzr
 def collect_command_names(self):
     """Collect names of available bzr commands."""
     from bzrlib import commands as _mod_commands
     names = list(_mod_commands.all_command_names())
     self.cmds_dict = dict(
         (n, _mod_commands.get_cmd_object(n)) for n in names)
     # Find the commands for each category, public or otherwise
     builtins = _mod_commands.builtin_command_names()
     self.all_cmds = {'All': []}
     self.public_cmds = {'All': []}
     for name, cmd in self.cmds_dict.iteritems():
         # If a command is builtin, we always put it into the Core
         # category, even if overridden in a plugin
         if name in builtins:
             category = 'Core'
         else:
             category = cmd.plugin_name()
         self.all_cmds['All'].append(name)
         self.all_cmds.setdefault(category, []).append(name)
         if not cmd.hidden:
             self.public_cmds['All'].append(name)
             self.public_cmds.setdefault(category, []).append(name)
     # Sort them
     for category in self.all_cmds:
         self.all_cmds[category].sort()
         try:
             self.public_cmds[category].sort()
         except KeyError:
             # no public commands - that's ok
             pass
Exemple #4
0
 def test_all_commands_have_help(self):
     commands._register_builtin_commands()
     commands_without_help = set()
     base_doc = inspect.getdoc(commands.Command)
     for cmd_name in commands.all_command_names():
         cmd = commands.get_cmd_object(cmd_name)
         cmd_help = cmd.help()
         if not cmd_help or cmd_help == base_doc:
             commands_without_help.append(cmd_name)
     self.assertLength(0, commands_without_help)
Exemple #5
0
 def test_all_commands_have_help(self):
     commands._register_builtin_commands()
     commands_without_help = set()
     base_doc = inspect.getdoc(commands.Command)
     for cmd_name in commands.all_command_names():
         cmd = commands.get_cmd_object(cmd_name)
         cmd_help = cmd.help()
         if not cmd_help or cmd_help == base_doc:
             commands_without_help.append(cmd_name)
     self.assertLength(0, commands_without_help)
Exemple #6
0
    def test_fires_on_all_command_names(self):
        # The list_commands() hook fires when all_command_names() is invoked.
        hook_calls = []
        commands.install_bzr_command_hooks()

        def list_my_commands(cmd_names):
            hook_calls.append("called")
            cmd_names.update(["foo", "bar"])
            return cmd_names

        commands.Command.hooks.install_named_hook("list_commands", list_my_commands, None)
        # Get a command, which should not trigger the hook.
        cmd = commands.get_cmd_object("info")
        self.assertEqual([], hook_calls)
        # Get all command classes (for docs and shell completion).
        cmds = list(commands.all_command_names())
        self.assertEqual(["called"], hook_calls)
        self.assertSubset(["foo", "bar"], cmds)
Exemple #7
0
    def complete_cmdname(self):

        cmds = []

        for cmdname in commands.all_command_names():
            cmdclass = commands.get_cmd_object(cmdname)
            if not complete_hidden_commands and cmdclass.hidden:
                continue
            cmds.append(cmdname)
            if complete_command_aliases:
                for alias in cmdclass.aliases:
                    if cmdname.startswith(alias):
                        continue
                    cmds.append(alias)

        for alias in config.GlobalConfig().get_aliases().keys():
            cmds.append(alias)

        return add_extra_space(self.filter(cmds))
Exemple #8
0
    def test_fires_on_all_command_names(self):
        # The list_commands() hook fires when all_command_names() is invoked.
        hook_calls = []
        commands.install_bzr_command_hooks()

        def list_my_commands(cmd_names):
            hook_calls.append('called')
            cmd_names.update(['foo', 'bar'])
            return cmd_names

        commands.Command.hooks.install_named_hook("list_commands",
                                                  list_my_commands, None)
        # Get a command, which should not trigger the hook.
        cmd = commands.get_cmd_object('info')
        self.assertEqual([], hook_calls)
        # Get all command classes (for docs and shell completion).
        cmds = list(commands.all_command_names())
        self.assertEqual(['called'], hook_calls)
        self.assertSubset(['foo', 'bar'], cmds)
Exemple #9
0
def _help_commands_to_text(topic):
    """Generate the help text for the list of commands"""
    out = []
    if topic == 'hidden-commands':
        hidden = True
    else:
        hidden = False
    names = list(_mod_commands.all_command_names())
    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
    shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
    max_name = max(len(n) for n, o in shown_commands)
    indent = ' ' * (max_name + 1)
    width = osutils.terminal_width()
    if width is None:
        width = osutils.default_terminal_width
    # we need one extra space for terminals that wrap on last char
    width = width - 1

    for cmd_name, cmd_object in sorted(shown_commands):
        plugin_name = cmd_object.plugin_name()
        if plugin_name is None:
            plugin_name = ''
        else:
            plugin_name = ' [%s]' % plugin_name

        cmd_help = cmd_object.help()
        if cmd_help:
            firstline = cmd_help.split('\n', 1)[0]
        else:
            firstline = ''
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
        lines = utextwrap.wrap(
            helpstring, subsequent_indent=indent,
            width=width,
            break_long_words=False)
        for line in lines:
            out.append(line + '\n')
    return ''.join(out)
Exemple #10
0
 def commands(self):
     for name in sorted(commands.all_command_names()):
         self.command(name)
Exemple #11
0
 def commands(self):
     for name in sorted(commands.all_command_names()):
         self.command(name)