Beispiel #1
0
    def test_help_loads(self):
        app = Application()
        with mock.patch('azure.cli.core.commands.arm.APPLICATION', app):
            from azure.cli.core.commands.arm import add_id_parameters
            parser_dict = {}
            cmd_tbl = app.configuration.get_command_table()
            app.parser.load_command_table(cmd_tbl)
            for cmd in cmd_tbl:
                try:
                    app.configuration.load_params(cmd)
                except KeyError:
                    pass
            app.register(app.COMMAND_TABLE_PARAMS_LOADED, add_id_parameters)
            app.raise_event(app.COMMAND_TABLE_PARAMS_LOADED, command_table=cmd_tbl)
            app.parser.load_command_table(cmd_tbl)
            _store_parsers(app.parser, parser_dict)

            for name, parser in parser_dict.items():
                try:
                    help_file = _help.GroupHelpFile(name, parser) \
                        if _is_group(parser) \
                        else _help.CommandHelpFile(name, parser)
                    help_file.load(parser)
                except Exception as ex:
                    raise _help.HelpAuthoringException('{}, {}'.format(name, ex))

            extras = [k for k in azure.cli.core.help_files.helps.keys() if k not in parser_dict]
            self.assertTrue(len(extras) == 0,
                            'Found help files that don\'t map to a command: '+ str(extras))
Beispiel #2
0
    def test_help_loads(self):
        app = Application()
        app.initialize(Configuration())
        with mock.patch('azure.cli.core.commands.arm.APPLICATION', app):
            from azure.cli.core.commands.arm import add_id_parameters
            parser_dict = {}
            cmd_tbl = app.configuration.get_command_table()
            app.parser.load_command_table(cmd_tbl)
            for cmd in cmd_tbl:
                try:
                    app.configuration.load_params(cmd)
                except KeyError:
                    pass
            app.register(app.COMMAND_TABLE_PARAMS_LOADED, add_id_parameters)
            app.raise_event(app.COMMAND_TABLE_PARAMS_LOADED,
                            command_table=cmd_tbl)
            app.parser.load_command_table(cmd_tbl)
            _store_parsers(app.parser, parser_dict)

            for name, parser in parser_dict.items():
                try:
                    help_file = _help.GroupHelpFile(name, parser) \
                        if _is_group(parser) \
                        else _help.CommandHelpFile(name, parser)
                    help_file.load(parser)
                except Exception as ex:
                    raise _help.HelpAuthoringException('{}, {}'.format(
                        name, ex))
    def test_help_loads(self):
        parser_dict = {}
        _store_parsers(APPLICATION.parser, parser_dict)

        for name, parser in parser_dict.items():
            try:
                help_file = _help.GroupHelpFile(name, parser) \
                    if _is_group(parser) \
                    else _help.CommandHelpFile(name, parser)
                help_file.load(parser)
            except Exception as ex:
                raise _help.HelpAuthoringException('{}, {}'.format(name, ex))

        extras = [k for k in azure.cli.core.help_files.helps.keys() if k not in parser_dict]
        self.assertTrue(len(extras) == 0,
                        'Found help files that don\'t map to a command: '+ str(extras))
    def make_rst(self):
        INDENT = '   '
        DOUBLEINDENT = INDENT * 2
        parser_keys = []
        parser_values = []
        sub_parser_keys = []
        sub_parser_values = []
        _store_parsers(app.parser, parser_keys, parser_values, sub_parser_keys,
                       sub_parser_values)
        for cmd, parser in zip(parser_keys, parser_values):
            if cmd not in sub_parser_keys:
                sub_parser_keys.append(cmd)
                sub_parser_values.append(parser)
        doc_source_map = _load_doc_source_map()
        help_files = []
        for cmd, parser in zip(sub_parser_keys, sub_parser_values):
            try:
                help_file = _help.GroupHelpFile(cmd, parser) if _is_group(
                    parser) else _help.CommandHelpFile(cmd, parser)
                help_file.load(parser)
                help_files.append(help_file)
            except Exception as ex:
                print("Skipped '{}' due to '{}'".format(cmd, ex))
        help_files = sorted(help_files, key=lambda x: x.command)

        for help_file in help_files:
            is_command = isinstance(help_file, _help.CommandHelpFile)
            yield '.. cli{}:: {}'.format(
                'command' if is_command else 'group',
                help_file.command if help_file.command else
                'az')  #it is top level group az if command is empty
            yield ''
            yield '{}:summary: {}'.format(INDENT, help_file.short_summary)
            yield '{}:description: {}'.format(INDENT, help_file.long_summary)
            if not is_command:
                top_group_name = help_file.command.split(
                )[0] if help_file.command else 'az'
                yield '{}:docsource: {}'.format(
                    INDENT, doc_source_map[top_group_name]
                    if top_group_name in doc_source_map else '')
            else:
                top_command_name = help_file.command.split(
                )[0] if help_file.command else ''
                if top_command_name in doc_source_map:
                    yield '{}:docsource: {}'.format(
                        INDENT, doc_source_map[top_command_name])
            yield ''

            if is_command and help_file.parameters:
                group_registry = _help.ArgumentGroupRegistry([
                    p.group_name for p in help_file.parameters if p.group_name
                ])

                for arg in sorted(
                        help_file.parameters,
                        key=lambda p: group_registry.get_group_priority(
                            p.group_name) + str(not p.required) + p.name):
                    yield '{}.. cliarg:: {}'.format(INDENT, arg.name)
                    yield ''
                    yield '{}:required: {}'.format(DOUBLEINDENT, arg.required)
                    short_summary = arg.short_summary or ''
                    possible_values_index = short_summary.find(
                        ' Possible values include')
                    short_summary = short_summary[
                        0:possible_values_index
                        if possible_values_index >= 0 else len(short_summary)]
                    short_summary = short_summary.strip()
                    yield '{}:summary: {}'.format(DOUBLEINDENT, short_summary)
                    yield '{}:description: {}'.format(DOUBLEINDENT,
                                                      arg.long_summary)
                    if arg.choices:
                        yield '{}:values: {}'.format(
                            DOUBLEINDENT,
                            ', '.join(sorted([str(x) for x in arg.choices])))
                    if arg.default and arg.default != argparse.SUPPRESS:
                        yield '{}:default: {}'.format(DOUBLEINDENT,
                                                      arg.default)
                    if arg.value_sources:
                        yield '{}:source: {}'.format(
                            DOUBLEINDENT, ', '.join(arg.value_sources))
                    yield ''
            yield ''
            if len(help_file.examples) > 0:
                for e in help_file.examples:
                    yield '{}.. cliexample:: {}'.format(INDENT, e.name)
                    yield ''
                    yield DOUBLEINDENT + e.text
                    yield ''