Example #1
0
 def get_text(self):
     """Get topic content."""
     stream = StringIO()
     result = []
     for name in self.controller.get_command_names():
         command = self.controller.get_command(name)
         help_topic = self.controller.get_help_topic(name)
         if not help_topic and command:
             help_topic = CommandHelpTopic(command)
             if self.controller is not None:
                 help_topic.controller = self.controller
         summary = ""
         if help_topic:
             summary = help_topic.get_summary()
         if self.include_command(command):
             result.append((name, summary))
     result.sort(key=lambda item: item[0])
     print_columns(stream, result)
     return stream.getvalue()
Example #2
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,)
Example #3
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))