Esempio 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
Esempio 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',
        )
Esempio 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',
        )
Esempio n. 4
0
    def test_simple_element(self):
        elements = {'foo': 'bar'}
        text = elements_as_text(elements)

        self.assertEqual(text, '\t  foo                    bar\n')
Esempio 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)