Example #1
0
    def __init__(self, options=None, commands=None, positionals=None):
        self.options = OrderedDict()
        self.add_option("__awwparse_help", HelpOption())
        self.add_options(self.__class__.options)
        if options is not None:
            self.add_options(options)

        self.commands = OrderedDict()
        self.add_commands(self.__class__.commands)
        if commands is not None:
            self.add_commands(commands)

        self.positionals = parse_positional_signature(
            force_list(self.__class__.positionals),
            require_metavar=True
        )
        if positionals is not None:
            self.add_positionals(positionals)

        self.parent = None

        signature = Signature.from_method(self.main)
        if signature.annotations:
            self._populate_from_signature(self, signature)

        for name in dir(self):
            try:
                attribute = getattr(self, name)
            except AttributeError:
                # maybe raised by properties; can be safely ignored
                continue
            if isinstance(attribute, Command):
                if not isinstance(attribute.main, MethodType):
                    attribute.main = partial(attribute.main, self)
                self.add_command(name, attribute)
Example #2
0
 def test_force_list(self):
     self.assert_equal(force_list(1), [1])
     self.assert_equal(force_list("abc"), ["a", "b", "c"])