#!/usr/bin/env python3
"""Prepare private glab fixtures; never upload generated config.yml files.
Requires PyYAML. Removes null defaults, which glab otherwise treats as literal paths.
"""
import pathlib,yaml,sys
root=pathlib.Path(sys.argv[1])
src=yaml.safe_load((root/'source-config/config.yml').read_text())
def clean(x):
    return {k:clean(v) for k,v in x.items() if v is not None} if isinstance(x,dict) else x
for name in ['signed-out']:
    p=root/name/'glab';p.mkdir(parents=True,exist_ok=True)
    d=clean({**src,'hosts':dict(src.get('hosts',{}))})
    if name=='signed-out':d['hosts']={}
    if name!='signed-in':
        d['hosts']['gitlab.invalid.example']={'token':'deliberately-invalid-fixture-token','api_host':'gitlab.invalid.example','api_protocol':'https','git_protocol':'https'}
        d['host']='gitlab.invalid.example'
    else:d['host']='gitlab.com'
    f=p/'config.yml';f.write_text(yaml.safe_dump(d));f.chmod(0o600)
