#!/usr/bin/env python
import cproc.wrapper
import argparse
import json


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Spawn a process environment.')
    parser.add_argument('pinfo', type=str,
                        help='Path to a cproc process info JSON file')
    parser.add_argument('-p', '--parent', action='store_true',
                        help='Run the parent process of the captured process')
    parser.add_argument('-t', '--toplevel', action='store_true',
                        help='Run the toplevel process of the captured process')
    parser.add_argument('-e', '--inherit-env', action='store_true',
                        help='Use current environment variables as base to be overwritten')
    args = parser.parse_args()
    pinfo = json.load(open(args.pinfo))
    cproc.wrapper.spawn_process(pinfo, parent=args.parent, toplevel=args.toplevel, inherit_env=args.inherit_env)
