#!/usr/bin/env python3

import argparse
import pprint
import json
import knc_loader


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("filename")
    parser.add_argument("--format", default='yaml', choices=['yaml', 'json', 'dict'])
    args = parser.parse_args()

    app = knc_loader.app(args.filename)

    if args.format == 'yaml':
        try:
            import yaml
        except ImportError:
            print()
            print('warning: --format=yaml but pyyaml is not installed, assuming --format=json instead')
            print('suggest running `pip3 install pyyaml`')
            print()
            args.format = 'json'

    if args.format == 'yaml':
        print(yaml.dump(app.config))
    elif args.format == 'json':
        print(json.dumps(app.config, indent=2, sort_keys=True))
    else:
        pprint.pprint(app.config)
