Beispiel #1
0
    def run(self, topic=None):
        """
        Show help for the C{bzrlib.commands.Command} or L{HelpTopic} matching
        C{name}.

        @param topic: Optionally, the name of the topic to show.  Default is
            C{basic}.
        """
        if topic is None:
            topic = "basic"
        text = None
        command = self.controller.get_command(topic)
        help_topic = self.controller.get_help_topic(topic)
        if help_topic:
            text = help_topic.get_text().strip()
        elif command:
            help_topic = CommandHelpTopic(command)
            help_topic.controller = self.controller
            text = help_topic.get_text()
        if text:
            print >>self.outf, text
        elif not (command or help_topic):
            print >>self.outf, "%s is an unknown command or topic." % (topic,)
Beispiel #2
0
    def test_get_help_contents(self):
        """
        L{CommandHelpTopic} loads topic summary and text from a
        C{bzrlib.commands.Command}.
        """
        command = self.factory.create_command("fake-command")
        command.name = lambda: "fake-command"
        help_topic = CommandHelpTopic(command)
        help_topic.controller = self.factory.controller
        self.assertEquals(help_topic.get_summary(), "Summary text.")
        expected = dedent("""\
            Purpose: Summary text.
            Usage:   test-program fake-command

            Options:
              ...

            Description:
              Long descriptive text that
              spans multiples lines.
            """)
        self.assertThat(
            help_topic.get_text() + "\n",
            DocTestMatches(expected, doctest.ELLIPSIS))