Exemplo n.º 1
0
    def get_help_text(self) -> str:
        """ Returns the help output in plain text format."""

        txt = ''
        for name, info in self.commands.items():
            description = info.get_description()
            attributes = info.get_attributes()
            elements = info.get_elements()

            command_txt = "\t{0: <22} {1}\n".format(name, description)

            if attributes:
                command_txt = ''.join([command_txt, "\t Attributes:\n"])

                for attrname, attrdesc in attributes.items():
                    attr_txt = "\t  {0: <22} {1}\n".format(attrname, attrdesc)
                    command_txt = ''.join([command_txt, attr_txt])

            if elements:
                command_txt = ''.join([
                    command_txt,
                    "\t Elements:\n",
                    elements_as_text(elements),
                ])

            txt += command_txt

        return txt
Exemplo n.º 2
0
    def test_simple_elements(self):
        elements = OrderedDict([('foo', 'bar'), ('lorem', 'ipsum')])
        text = elements_as_text(elements)

        self.assertEqual(
            text,
            '\t  foo                    bar\n'
            '\t  lorem                  ipsum\n',
        )
Exemplo n.º 3
0
    def test_elements(self):
        elements = OrderedDict([
            ('foo', 'bar'),
            (
                'lorem',
                OrderedDict([
                    ('dolor', 'sit amet'),
                    ('consectetur', 'adipiscing elit'),
                ]),
            ),
        ])
        text = elements_as_text(elements)

        self.assertEqual(
            text,
            '\t  foo                    bar\n'
            '\t  lorem                  \n'
            '\t    dolor                  sit amet\n'
            '\t    consectetur            adipiscing elit\n',
        )
Exemplo n.º 4
0
    def test_simple_element(self):
        elements = {'foo': 'bar'}
        text = elements_as_text(elements)

        self.assertEqual(text, '\t  foo                    bar\n')
Exemplo n.º 5
0
 def elements_as_text(self, elems: Dict, indent: int = 2) -> str:
     """ Returns the elems dictionary as formatted plain text. """
     return elements_as_text(elems, indent)