INNER CODE UNIT · Python

extract

torognes/vsearch · completion/scripts/extract_cli_options.py:48

def extract(path: str) -> dict:
    with open(path, encoding='utf-8') as handle:
        text = strip_comments(handle.read())

    options = {
        '--' + name: needs_arg == 'true'
        for name, needs_arg in re.findall(
            r'\{\s*"([^"]+)"\s*,\s*(true|false)\s*\}',
            table_body(text, 'option_specs =', path))
    }
    if not options:
        sys.exit(f'{path}: option_specs parsed as empty.')

    # Rows are terminated by -1 and no option index is negative, so
    # splitting on the literal is safe.
    commands = {}
    for row in table_body(text, 'valid_options =', path).split('-1'):
        names = re.findall(r'option_([A-Za-z0-9_]+)', row)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…