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


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Capture a process environment.')
    parser.add_argument('pid', type=int,
                        help='The PID of the process to capture')
    parser.add_argument('-t', '--toplevel-tree', action='store_true',
                        help='Include the whole process tree of the process')
    parser.add_argument('-c', '--child-tree', action='store_true',
                        help='Include the tree of children from the process')
    parser.add_argument('-p', '--pretty', action='store_true',
                        help='Output the result in pretty JSON')
    args = parser.parse_args()
    print(json.dumps(
        cproc.wrapper.capture(args.pid, toplevel_tree=args.toplevel_tree, child_tree=args.child_tree),
        indent=None if args.pretty is False else 4))
