def main()

in scripts/add_map_plugin.py [0:0]


def main():

    default_arg_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'map_config/default_args.json')
    with open(default_arg_path, 'r') as f:
        default_args = json.load(f)

    parser = argparse.ArgumentParser(description="Arguments for default/custom usage of map_plugin tool.")
    
    subparsers = parser.add_subparsers(help='types of usage')

    # default tool usage
    default_parser = subparsers.add_parser("default")
    default_parser.add_argument("--world_name", required=True, help="takes a default world_name, each referring to an existing aws-robotics worlds", choices=list(default_args.keys()), type=str)

    # custom tool usage
    custom_parser = subparsers.add_parser("custom")
    custom_parser.add_argument("-c", "--config_file", required=True, help="config file (.rb) for the map plugin parameters", type=str)
    custom_parser.add_argument("-w", "--world_file", required=True, help="path to the original world file", type=str)
    custom_parser.add_argument("-o", "--output_file", required=True, help="output path of the new world file", type=str)

    args = process_args(parser.parse_args(), default_args)

    plugin_tool_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "genmap.sh")
    cmd = ' '.join([plugin_tool_path] + args)

    try:
        out = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        print("Execution failed with exitcode {0}\n\n{1}".format(e.returncode, e.output))
        sys.exit(e.returncode)
    else:
        print("{}\n".format(out))