"""Export a checked map to a NEW local JSON file. No Resolve writes."""
import argparse
from resolve_api_connection import connect
from resolve_api_timeline import collect_map, export_map, dumps


def main(argv=None):
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("--output", help="Absolute .json path; existing files are never overwritten")
    a = p.parse_args(argv)
    report = collect_map(connect())
    if a.output is None:
        print(dumps(report))  # Preview only. Shell redirection has its own overwrite rules.
    else:
        print(dumps(export_map(report, a.output)))
    return 0 if report["complete"] else 2


if __name__ == "__main__":
    raise SystemExit(main())
