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()
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))