def enhance_parser(parser, subparsers):
    """Take a basic (nonversioned) parser and enhance it with
    commands and options specific for this version of API.

    :param parser: top level parser :param subparsers: top level
        parser's subparsers collection where subcommands will go
    """
    for command_module in COMMAND_MODULES:
        utils.define_commands_from_module(subparsers, command_module)
Beispiel #2
0
def enhance_parser(parser, subparsers):
    '''Take a basic (nonversioned) parser and enhance it with
    commands and options specific for this version of API.

    :param parser: top level parser :param subparsers: top level
        parser's subparsers collection where subcommands will go
    '''
    for command_module in COMMAND_MODULES:
        utils.define_commands_from_module(subparsers, command_module)
    def test_define_commands_from_module(self):
        subparsers = mock.Mock()
        subparser = mock.MagicMock()
        subparsers.add_parser.return_value = subparser
        dummy_module = self.dummy_command_module()

        utils.define_commands_from_module(subparsers, dummy_module)
        subparsers.add_parser.assert_called_with(
            'dummy-list', help="Docstring.", description="Docstring.")
        subparser.add_argument.assert_called_with(
            '-a', metavar='<NUMBER>', help="Add a number.")
        subparser.set_defaults.assert_called_with(
            func=dummy_module.do_dummy_list)
    def _parser(self, version):
        '''Create a top level argument parser.

        :param version: version of Tuskar API (and corresponding CLI
            commands) to use
        :return: main parser and subparsers
        :rtype: (Parser, Subparsers)
        '''
        parser = self._nonversioned_parser()
        subparsers = parser.add_subparsers(metavar='<subcommand>')
        versioned_shell = utils.import_versioned_module(version, 'shell')
        versioned_shell.enhance_parser(parser, subparsers)
        utils.define_commands_from_module(subparsers, self)
        return parser, subparsers