def parse_config(shell, name, config, functions=[], ignore_opts=False):
    functions.append('')
    functions.append('%s () {' % name)

    # Get subparsers config.
    subparsers_config = config.get('subparsers', {})
    if 'parsers' in subparsers_config:
        subparsers_config = subparsers_config['parsers']
    subparsers = list(subparsers_config.keys())
    subparsers_desc = [
        '"%s:%s"' % (subparser, subparser_conf.get('description', 'No description.'))
        for subparser, subparser_conf in subparsers_config.items()]

    # Get options and args
    options = ['--%s' % clg.format_optname(opt)
        for opt in config.get('options', {}).keys()]
    options_desc = [
        '"--%s:%s"' % ( clg.format_optname(opt),
            opt_conf.get('help', 'No description'))
        for opt, opt_conf in config.get('options', {}).items()]
    if config.get('add_help', True):
        options.append('--help')
        options_desc.append('"--help:Show this help message and exit."')
    if ignore_opts and subparsers:
        options = []
        options_desc = []
    arguments = list(config.get('args', {}).keys())

    # Generate command function.
    functions.append('    options=(%s)' % ' '.join(options))
    functions.append('    args=(%s)' % ' '.join(
        clg.format_optname(arg) for arg in arguments))
    functions.append('    subcommands=(%s)' % ' '.join(subparsers))
    if shell == 'zsh' and not args.simple:
        functions.append('    options_desc=(%s)' % '\n'.join(options_desc))
        functions.append('    subcommands_desc=(%s)' % '\n'.join(subparsers_desc))

    # Add parse_command execution
    functions.append('    parse_command %s %s' % (name,
        {'bash': 1, 'zsh': 2}[shell] if name == '_%s' % args.prog else '$1'))
    functions.append('}')

    for subparser, config in subparsers_config.items():
        functions = parse_config(
            shell, '%s_%s' % (name, subparser), config, functions, ignore_opts)

    return functions
dataset/ETHPy150Open fmenabe/python-clg/gencomp.py/parse_config/original