INNER CODE UNIT · Python
load
torognes/vsearch · completion/scripts/check_option_drift.py:44
def load(cli_path: str, spec_path: str) -> tuple:
with open(cli_path, encoding='utf-8') as handle:
cli = json.load(handle)
with open(spec_path, encoding='utf-8') as handle:
spec = yaml.safe_load(handle)
options = {ALIASES.get(name, name): needs_arg
for name, needs_arg in cli['options'].items()}
commands = {}
for command, accepted in cli['commands'].items():
# An alias row accepts the same options as the row it aliases;
# merge them so --help is compared once.
name = ALIASES.get(command, command)
merged = set(commands.get(name, ())) | {ALIASES.get(o, o) for o in accepted}
commands[name] = sorted(merged)
return options, commands, spec