Пример #1
0
def get_all_help(cli_ctx, skip=True):
    invoker = cli_ctx.invocation
    help_ctx = cli_ctx.help_cls(cli_ctx)
    if not invoker:
        raise CLIError('CLI context does not contain invocation.')

    parser_keys = []
    parser_values = []
    sub_parser_keys = []
    sub_parser_values = []
    _store_parsers(invoker.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)
    help_files = []
    help_errors = {}
    for cmd, parser in zip(sub_parser_keys, sub_parser_values):
        try:
            help_ctx.update_loaders_with_help_file_contents(cmd.split())
            help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \
                else CliCommandHelpFile(help_ctx, cmd, parser)
            help_file.load(parser)
            help_files.append(help_file)
        except Exception as ex:  # pylint: disable=broad-except
            if skip:
                logger.warning("Skipping '%s': %s", cmd, ex)
            else:
                help_errors[cmd] = "Error '{}': {}".format(cmd, ex)
    if help_errors:
        raise CLIError(help_errors)
    help_files = sorted(help_files, key=lambda x: x.command)
    return help_files
Пример #2
0
def get_all_help(cli_ctx):
    invoker = cli_ctx.invocation
    help_ctx = cli_ctx.help_cls(cli_ctx)
    if not invoker:
        raise CLIError('CLI context does not contain invocation.')

    parser_keys = []
    parser_values = []
    sub_parser_keys = []
    sub_parser_values = []
    _store_parsers(invoker.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)
    help_files = []
    for cmd, parser in zip(sub_parser_keys, sub_parser_values):
        try:
            help_ctx.update_loaders_with_help_file_contents(cmd.split())
            help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \
                else CliCommandHelpFile(help_ctx, cmd, parser)
            help_file.load(parser)
            help_files.append(help_file)
        except Exception as ex:  # pylint: disable=broad-except
            print("Skipped '{}' due to '{}'".format(cmd, ex))
    help_files = sorted(help_files, key=lambda x: x.command)
    return help_files
Пример #3
0
def get_all_help(cli_ctx):
    invoker = cli_ctx.invocation
    help_ctx = cli_ctx.help_cls(cli_ctx)
    if not invoker:
        raise CLIError('CLI context does not contain invocation.')

    parser_keys = []
    parser_values = []
    sub_parser_keys = []
    sub_parser_values = []
    _store_parsers(invoker.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)
    help_files = []
    for cmd, parser in zip(sub_parser_keys, sub_parser_values):
        if cmd in loaded_helps:
            try:
                help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \
                    else CliCommandHelpFile(help_ctx, cmd, parser)
                help_file.load(parser)
                help_files.append(help_file)
            except Exception as ex:  # pylint: disable=broad-except
                print("Skipped '{}' due to '{}'".format(cmd, ex))
    help_files = sorted(help_files, key=lambda x: x.command)
    assert {help_file.command for help_file in help_files} == set(loaded_helps.keys())
    print("Loaded {} help files".format(len(help_files)))
    return help_files
Пример #4
0
def get_all_help(cli_ctx):
    invoker = cli_ctx.invocation
    help_ctx = cli_ctx.help_cls(cli_ctx)
    if not invoker:
        raise CLIError('CLI context does not contain invocation.')

    parser_keys = []
    parser_values = []
    sub_parser_keys = []
    sub_parser_values = []
    _store_parsers(invoker.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)
    help_files = []
    for cmd, parser in zip(sub_parser_keys, sub_parser_values):
        if cmd in loaded_helps:
            try:
                help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \
                    else CliCommandHelpFile(help_ctx, cmd, parser)
                help_file.load(parser)
                help_files.append(help_file)
            except Exception as ex:  # pylint: disable=broad-except
                print("Skipped '{}' due to '{}'".format(cmd, ex))
    help_files = sorted(help_files, key=lambda x: x.command)
    assert {help_file.command
            for help_file in help_files} == set(loaded_helps.keys())
    print("Loaded {} help files".format(len(help_files)))
    return help_files
Пример #5
0
def get_all_help(cli_ctx, skip=True):
    invoker = cli_ctx.invocation
    help_ctx = cli_ctx.help_cls(cli_ctx)
    if not invoker:
        raise CLIError('CLI context does not contain invocation.')

    parser_keys = []
    parser_values = []
    sub_parser_keys = []
    sub_parser_values = []
    _store_parsers(invoker.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)
    help_files = []
    help_errors = {}
    for cmd, parser in zip(sub_parser_keys, sub_parser_values):
        try:
            help_ctx.update_loaders_with_help_file_contents(cmd.split())
            help_file = CliGroupHelpFile(help_ctx, cmd, parser) if _is_group(parser) \
                else CliCommandHelpFile(help_ctx, cmd, parser)
            help_file.load(parser)
            help_files.append(help_file)
        except Exception as ex:  # pylint: disable=broad-except
            if skip:
                logger.warning("Skipping '%s': %s", cmd, ex)
            else:
                help_errors[cmd] = "Error '{}': {}".format(cmd, ex)
    if help_errors:
        raise CLIError(help_errors)
    help_files = sorted(help_files, key=lambda x: x.command)
    return help_files