import yaml
import sys

def main(config_path):
    try:
        with open(config_path, 'r') as f:
            config = yaml.safe_load(f)

        if 'service_aliases' in config and config['service_aliases']:
            for key, value in config['service_aliases'].items():
                print(f"export SERVICE_ALIAS_{key.replace('-', '_')}='{value}'")

        if 'canvas_aliases' in config and config['canvas_aliases']:
            for key, value in config['canvas_aliases'].items():
                print(f"export CANVAS_ALIAS_{key.replace('-', '_')}='{value}'")

        if 'ignore_containers' in config and config['ignore_containers']:
            ignore_list = " ".join(config['ignore_containers'])
            print(f"export IGNORE_CONTAINERS='{ignore_list}'")

    except Exception as e:
        print(f"# Config load failed: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        main(sys.argv[1])
    else:
        print("# Usage: python load_config.py <path_to_config.yaml>", file=sys.stderr)
        sys.exit(1)
