Beispiel #1
0
def create_invoker_and_load_cmds_and_args(cli_ctx):
    invoker = cli_ctx.invocation_cls(cli_ctx=cli_ctx, commands_loader_cls=cli_ctx.commands_loader_cls,
                                     parser_cls=cli_ctx.parser_cls, help_cls=cli_ctx.help_cls)
    cli_ctx.invocation = invoker
    invoker.commands_loader.load_command_table(None)
    for command in invoker.commands_loader.command_table:
        invoker.commands_loader.load_arguments(command)
    invoker.parser.load_command_table(invoker.commands_loader)
    add_id_parameters(None, commands_loader=invoker.commands_loader)
Beispiel #2
0
    def dump_command_table(self, shell_ctx=None):
        """ dumps the command table """
        import timeit

        start_time = timeit.default_timer()
        shell_ctx = shell_ctx or self.shell_ctx
        main_loader = AzInteractiveCommandsLoader(shell_ctx.cli_ctx)

        main_loader.load_command_table(None)
        main_loader.load_arguments(None)
        add_id_parameters(None, commands_loader=main_loader)
        cmd_table = main_loader.command_table

        cmd_table_data = {}
        for command_name, cmd in cmd_table.items():

            try:
                command_description = cmd.description
                if callable(command_description):
                    command_description = command_description()

                # checking all the parameters for a single command
                parameter_metadata = {}
                for arg in cmd.arguments.values():
                    options = {
                        'name': [name for name in arg.options_list],
                        'required':
                        REQUIRED_TAG
                        if arg.type.settings.get('required') else '',
                        'help':
                        arg.type.settings.get('help') or ''
                    }
                    # the key is the first alias option
                    if arg.options_list:
                        parameter_metadata[arg.options_list[0]] = options

                cmd_table_data[command_name] = {
                    'parameters': parameter_metadata,
                    'help': command_description,
                    'examples': ''
                }
            except (ImportError, ValueError):
                pass

        load_help_files(cmd_table_data)
        elapsed = timeit.default_timer() - start_time
        logger.debug('Command table dumped: %s sec', elapsed)
        FreshTable.loader = main_loader

        # dump into the cache file
        command_file = shell_ctx.config.get_help_files()
        with open(os.path.join(get_cache_dir(shell_ctx), command_file),
                  'w') as help_file:
            json.dump(cmd_table_data,
                      help_file,
                      default=lambda x: x.target or '',
                      skipkeys=True)
Beispiel #3
0
    def dump_command_table(self, shell_ctx):
        """ dumps the command table """

        loader = shell_ctx.cli_ctx.invocation.commands_loader
        cmd_table = loader.load_command_table(None)
        loader.load_arguments('')

        data = {}
        for cmd in cmd_table:
            com_descrip = {}  # commands to their descriptions, examples, and parameter info
            param_descrip = {}  # parameters to their aliases, required, and descriptions

            try:
                command_description = cmd_table[cmd].description
                if callable(command_description):
                    command_description = command_description()

                com_descrip['help'] = command_description
                com_descrip['examples'] = ""

                # checking all the parameters for a single command
                for key in cmd_table[cmd].arguments:
                    required = ""
                    help_desc = ""

                    if cmd_table[cmd].arguments[key].type.settings.get('required'):
                        required = "[REQUIRED]"
                    if cmd_table[cmd].arguments[key].type.settings.get('help'):
                        help_desc = cmd_table[cmd].arguments[key].type.settings.get('help')

                    # checking aliasing
                    name_options = []
                    for name in cmd_table[cmd].arguments[key].options_list:
                        name_options.append(name)

                    options = {
                        'name': name_options,
                        'required': required,
                        'help': help_desc
                    }
                    # the key is the first alias option
                    param_descrip[cmd_table[cmd].arguments[key].options_list[0]] = options

                com_descrip['parameters'] = param_descrip
                data[cmd] = com_descrip
            except (ImportError, ValueError):
                pass

        add_id_parameters(cmd_table)
        self.load_help_files(data)

        self.command_table = cmd_table

        # dump into the cache file
        command_file = shell_ctx.config.get_help_files()
        with open(os.path.join(get_cache_dir(shell_ctx), command_file), 'w') as help_file:
            json.dump(data, help_file)
Beispiel #4
0
    def dump_command_table(self):
        """ dumps the command table """

        self.command_table = APPLICATION.configuration.get_command_table()
        command_file = config.CONFIGURATION.get_help_files()

        self.install_modules()
        add_id_parameters(self.command_table)

        data = {}
        for cmd in self.command_table:
            com_descrip = {}  # commands to their descriptions, examples, and parameter info
            param_descrip = {}  # parameters to their aliases, required, and descriptions

            try:
                command_description = self.command_table[cmd].description
                if callable(command_description):
                    command_description = command_description()

                com_descrip['help'] = command_description
                com_descrip['examples'] = ""

                # checking all the parameters for a single command
                for key in self.command_table[cmd].arguments:
                    required = ""
                    help_desc = ""

                    if self.command_table[cmd].arguments[key].type.settings.get('required'):
                        required = "[REQUIRED]"
                    if self.command_table[cmd].arguments[key].type.settings.get('help'):
                        help_desc = self.command_table[cmd].arguments[key].type.settings.get('help')

                    # checking aliasing
                    name_options = []
                    for name in self.command_table[cmd].arguments[key].options_list:
                        name_options.append(name)

                    options = {
                        'name': name_options,
                        'required': required,
                        'help': help_desc
                    }
                    # the key is the first alias option
                    param_descrip[self.command_table[cmd].arguments[key].options_list[0]] = options

                com_descrip['parameters'] = param_descrip
                data[cmd] = com_descrip
            except (ImportError, ValueError):
                pass

        self.load_help_files(data)

        # dump into the cache file
        with open(os.path.join(get_cache_dir(), command_file), 'w') as help_file:
            json.dump(data, help_file)
Beispiel #5
0
    def dump_command_table(self, shell_ctx):
        """ dumps the command table """
        import timeit

        start_time = timeit.default_timer()
        main_loader = AzInteractiveCommandsLoader(shell_ctx.cli_ctx)

        main_loader.load_command_table(None)
        main_loader.load_arguments()
        add_id_parameters(main_loader.command_table)
        cmd_table = main_loader.command_table

        cmd_table_data = {}
        for command_name, cmd in cmd_table.items():

            try:
                command_description = cmd.description
                if callable(command_description):
                    command_description = command_description()

                # checking all the parameters for a single command
                parameter_metadata = {}
                for key in cmd.arguments:
                    options = {
                        'name':
                        [name for name in cmd.arguments[key].options_list],
                        'required':
                        '[REQUIRED]'
                        if cmd.arguments[key].type.settings.get('required')
                        else '',
                        'help':
                        cmd.arguments[key].type.settings.get('help') or ''
                    }
                    # the key is the first alias option
                    parameter_metadata[
                        cmd.arguments[key].options_list[0]] = options

                cmd_table_data[command_name] = {
                    'parameters': parameter_metadata,
                    'help': command_description,
                    'examples': ''
                }
            except (ImportError, ValueError):
                pass

        self.load_help_files(cmd_table_data)
        elapsed = timeit.default_timer() - start_time
        logger.debug('Command table dumped: {} sec'.format(elapsed))
        self.command_table = main_loader.command_table

        # dump into the cache file
        command_file = shell_ctx.config.get_help_files()
        with open(os.path.join(get_cache_dir(shell_ctx), command_file),
                  'w') as help_file:
            json.dump(cmd_table_data, help_file)
Beispiel #6
0
    def dump_command_table(self, shell_ctx=None):
        """ dumps the command table """
        import timeit

        start_time = timeit.default_timer()
        shell_ctx = shell_ctx or self.shell_ctx
        main_loader = AzInteractiveCommandsLoader(shell_ctx.cli_ctx)

        main_loader.load_command_table(None)
        main_loader.load_arguments(None)
        add_id_parameters(None, commands_loader=main_loader)
        cmd_table = main_loader.command_table

        cmd_table_data = {}
        for command_name, cmd in cmd_table.items():

            try:
                command_description = cmd.description
                if callable(command_description):
                    command_description = command_description()

                # checking all the parameters for a single command
                parameter_metadata = {}
                for arg in cmd.arguments.values():
                    options = {
                        'name': [name for name in arg.options_list],
                        'required': REQUIRED_TAG if arg.type.settings.get('required') else '',
                        'help': arg.type.settings.get('help') or ''
                    }
                    # the key is the first alias option
                    if arg.options_list:
                        parameter_metadata[arg.options_list[0]] = options

                cmd_table_data[command_name] = {
                    'parameters': parameter_metadata,
                    'help': command_description,
                    'examples': ''
                }
            except (ImportError, ValueError):
                pass

        load_help_files(cmd_table_data)
        elapsed = timeit.default_timer() - start_time
        logger.debug('Command table dumped: %s sec', elapsed)
        FreshTable.loader = main_loader

        # dump into the cache file
        command_file = shell_ctx.config.get_help_files()
        with open(os.path.join(get_cache_dir(shell_ctx), command_file), 'w') as help_file:
            json.dump(cmd_table_data, help_file, default=lambda x: x.target or '', skipkeys=True)
Beispiel #7
0
def dump_no_help(modules):
    APPLICATION.initialize(Configuration())
    cmd_table = APPLICATION.configuration.get_command_table()

    exit_val = 0
    for cmd in cmd_table:
        cmd_table[cmd].load_arguments()

    for mod in modules:
        try:
            import_module('azure.cli.command_modules.' + mod).load_params(mod)
        except Exception as ex:
            print("EXCEPTION: " + str(mod))

    _update_command_definitions(cmd_table)
    add_id_parameters(cmd_table)

    with open(WHITE_DATA_FILE, 'r') as white:
        white_data = json.load(white)

    white_list_commands = set(white_data.get('commands', []))
    white_list_subgroups = set(white_data.get('subgroups', []))
    white_list_parameters = white_data.get('parameters', {})

    command_list = set()
    subgroups_list = set()
    parameters = {}
    for cmd in cmd_table:
        if not cmd_table[cmd].description and cmd not in helps and cmd not in white_list_commands:
            command_list.add(cmd)
            exit_val = 1
        group_name = " ".join(cmd.split()[:-1])
        if group_name not in helps:
            if group_name not in subgroups_list and group_name not in white_list_subgroups and group_name:
                exit_val = 1
                subgroups_list.add(group_name)

        param_list = set()
        for key in cmd_table[cmd].arguments:
            name = cmd_table[cmd].arguments[key].name
            if not cmd_table[cmd].arguments[key].type.settings.get('help') and \
                    name not in white_list_parameters.get(cmd, []):
                exit_val = 1
                param_list.add(name)
        if param_list:
            parameters[cmd] = param_list

    for cmd in helps:
        diction_help = yaml.load(helps[cmd])
        if "short-summary" in diction_help and "type" in diction_help:
            if diction_help["type"] == "command" and cmd in command_list:
                command_list.remove(cmd)
            elif diction_help["type"] == "group" and cmd in subgroups_list:
                subgroups_list.remove(cmd)
        if "parameters" in diction_help:
            for param in diction_help["parameters"]:
                if "short-summary" in param and param["name"].split()[0] in parameters:
                    parameters.pop(cmd, None)

    data = {
        "subgroups": subgroups_list,
        "commands": command_list,
        "parameters": parameters
    }

    return exit_val, data
Beispiel #8
0
def dump_command_table():
    """ dumps the command table """
    command_file = config.CONFIGURATION.get_help_files()

    install_modules()
    add_id_parameters(CMD_TABLE)

    data = {}
    for cmd in CMD_TABLE:
        com_descrip = {}
        param_descrip = {}
        command_description = CMD_TABLE[cmd].description
        if callable(command_description):
            command_description = command_description()
        com_descrip['help'] = command_description
        com_descrip['examples'] = ""

        for key in CMD_TABLE[cmd].arguments:
            required = ""
            help_desc = ""
            if CMD_TABLE[cmd].arguments[key].type.settings.get('required'):
                required = "[REQUIRED]"
            if CMD_TABLE[cmd].arguments[key].type.settings.get('help'):
                help_desc = CMD_TABLE[cmd].arguments[key].type.settings.get(
                    'help')

            name_options = []
            for name in CMD_TABLE[cmd].arguments[key].options_list:
                name_options.append(name)

            options = {
                'name': name_options,
                'required': required,
                'help': help_desc
            }
            param_descrip[
                CMD_TABLE[cmd].arguments[key].options_list[0]] = options

        com_descrip['parameters'] = param_descrip
        data[cmd] = com_descrip

    for cmd in helps:
        diction_help = yaml.load(helps[cmd])
        if "short-summary" in diction_help:
            if cmd in data:
                data[cmd]['help'] = diction_help["short-summary"]
            else:
                data[cmd] = {
                    'help': diction_help["short-summary"],
                    'parameters': {}
                }
            if callable(data[cmd]['help']):
                data[cmd]['help'] = data[cmd]['help']()

        if cmd not in data:
            print("Command: {} not in Command Table".format(cmd))
            continue

        if "parameters" in diction_help:
            for param in diction_help["parameters"]:
                if param["name"].split()[0] not in data[cmd]['parameters']:
                    options = {
                        'name': name_options,
                        'required': required,
                        'help': help_desc
                    }
                    data[cmd]['parameters'] = {
                        param["name"].split()[0]: options
                    }
                if "short-summary" in param:
                    data[cmd]['parameters'][param["name"].split()[0]]['help']\
                        = param["short-summary"]
        if "examples" in diction_help:
            examples = []
            for example in diction_help["examples"]:
                examples.append([example['name'], example['text']])
            data[cmd]['examples'] = examples

    with open(os.path.join(get_cache_dir(), command_file), 'w') as help_file:
        json.dump(data, help_file)
Beispiel #9
0
def dump_no_help(modules):
    APPLICATION.initialize(Configuration())
    cmd_table = APPLICATION.configuration.get_command_table()

    exit_val = 0
    for cmd in cmd_table:
        cmd_table[cmd].load_arguments()

    for mod in modules:
        try:
            import_module('azure.cli.command_modules.' + mod).load_params(mod)
        except Exception as ex:
            print("EXCEPTION: {} for module {}".format(ex, str(mod)))

    _update_command_definitions(cmd_table)
    add_id_parameters(cmd_table)

    with open(WHITE_DATA_FILE, 'r') as white:
        white_data = json.load(white)

    white_list_commands = set(white_data.get('commands', []))
    white_list_subgroups = set(white_data.get('subgroups', []))
    white_list_parameters = white_data.get('parameters', {})

    command_list = set()
    subgroups_list = set()
    parameters = {}
    for cmd in cmd_table:
        if not cmd_table[
                cmd].description and cmd not in helps and cmd not in white_list_commands:
            command_list.add(cmd)
            exit_val = 1
        group_name = " ".join(cmd.split()[:-1])
        if group_name not in helps:
            if group_name not in subgroups_list and group_name not in white_list_subgroups and group_name:
                exit_val = 1
                subgroups_list.add(group_name)

        param_list = set()
        for key in cmd_table[cmd].arguments:
            name = cmd_table[cmd].arguments[key].name
            if not cmd_table[cmd].arguments[key].type.settings.get(
                    'help') and name not in white_list_parameters.get(cmd, []):
                exit_val = 1
                param_list.add(name)
        if param_list:
            parameters[cmd] = param_list

    for cmd in helps:
        diction_help = yaml.load(helps[cmd])
        if "short-summary" in diction_help and "type" in diction_help:
            if diction_help["type"] == "command" and cmd in command_list:
                command_list.remove(cmd)
            elif diction_help["type"] == "group" and cmd in subgroups_list:
                subgroups_list.remove(cmd)
        if "parameters" in diction_help:
            for param in diction_help["parameters"]:
                if "short-summary" in param and param["name"].split(
                )[0] in parameters:
                    parameters.pop(cmd, None)

    data = {
        "subgroups": subgroups_list,
        "commands": command_list,
        "parameters": parameters
    }

    return exit_val, data
def dump_command_table():
    """ dumps the command table """
    command_file = config.CONFIGURATION.get_help_files()

    install_modules()
    add_id_parameters(CMD_TABLE)

    data = {}
    for cmd in CMD_TABLE:
        com_descrip = {}
        param_descrip = {}
        try:
            command_description = CMD_TABLE[cmd].description
            if callable(command_description):
                command_description = command_description()
            com_descrip['help'] = command_description
            com_descrip['examples'] = ""

            for key in CMD_TABLE[cmd].arguments:
                required = ""
                help_desc = ""
                if CMD_TABLE[cmd].arguments[key].type.settings.get('required'):
                    required = "[REQUIRED]"
                if CMD_TABLE[cmd].arguments[key].type.settings.get('help'):
                    help_desc = CMD_TABLE[cmd].arguments[key].type.settings.get('help')

                name_options = []
                for name in CMD_TABLE[cmd].arguments[key].options_list:
                    name_options.append(name)

                options = {
                    'name': name_options,
                    'required': required,
                    'help': help_desc
                }
                param_descrip[CMD_TABLE[cmd].arguments[key].options_list[0]] = options

            com_descrip['parameters'] = param_descrip
            data[cmd] = com_descrip
        except (ImportError, ValueError):
            pass

    for cmd in helps:
        diction_help = yaml.load(helps[cmd])
        if "short-summary" in diction_help:
            if cmd in data:
                data[cmd]['help'] = diction_help["short-summary"]
            else:
                data[cmd] = {
                    'help': diction_help["short-summary"],
                    'parameters': {}
                }
            if callable(data[cmd]['help']):
                data[cmd]['help'] = data[cmd]['help']()

        if cmd not in data:
            print("Command: {} not in Command Table".format(cmd))
            continue

        if "parameters" in diction_help:
            for param in diction_help["parameters"]:
                if param["name"].split()[0] not in data[cmd]['parameters']:
                    options = {
                        'name': name_options,
                        'required': required,
                        'help': help_desc
                    }
                    data[cmd]['parameters'] = {
                        param["name"].split()[0]: options
                    }
                if "short-summary" in param:
                    data[cmd]['parameters'][param["name"].split()[0]]['help']\
                        = param["short-summary"]
        if "examples" in diction_help:
            examples = []
            for example in diction_help["examples"]:
                examples.append([example['name'], example['text']])
            data[cmd]['examples'] = examples

    with open(os.path.join(get_cache_dir(), command_file), 'w') as help_file:
        json.dump(data, help_file)
Beispiel #11
0
    def dump_command_table(self):
        """ dumps the command table """

        self.command_table = APPLICATION.configuration.get_command_table()
        command_file = config.CONFIGURATION.get_help_files()

        self.install_modules()
        add_id_parameters(self.command_table)

        data = {}
        for cmd in self.command_table:
            com_descrip = {
            }  # commands to their descriptions, examples, and parameter info
            param_descrip = {
            }  # parameters to their aliases, required, and descriptions

            try:
                command_description = self.command_table[cmd].description
                if callable(command_description):
                    command_description = command_description()

                com_descrip['help'] = command_description
                com_descrip['examples'] = ""

                # checking all the parameters for a single command
                for key in self.command_table[cmd].arguments:
                    required = ""
                    help_desc = ""

                    if self.command_table[cmd].arguments[
                            key].type.settings.get('required'):
                        required = "[REQUIRED]"
                    if self.command_table[cmd].arguments[
                            key].type.settings.get('help'):
                        help_desc = self.command_table[cmd].arguments[
                            key].type.settings.get('help')

                    # checking aliasing
                    name_options = []
                    for name in self.command_table[cmd].arguments[
                            key].options_list:
                        name_options.append(name)

                    options = {
                        'name': name_options,
                        'required': required,
                        'help': help_desc
                    }
                    # the key is the first alias option
                    param_descrip[self.command_table[cmd].arguments[key].
                                  options_list[0]] = options

                com_descrip['parameters'] = param_descrip
                data[cmd] = com_descrip
            except (ImportError, ValueError):
                pass

        self.load_help_files(data)

        # dump into the cache file
        with open(os.path.join(get_cache_dir(), command_file),
                  'w') as help_file:
            json.dump(data, help_file)