#!/usr/bin/env python3

"""
Query the CIME config_machines.xml file
"""

from utils import check_minimum_python_version
check_minimum_python_version(3, 4)

import argparse, sys, pathlib

from query_cime import query_cime

###############################################################################
def parse_command_line(args, description):
###############################################################################
    parser = argparse.ArgumentParser(
        usage="""\n{0} <machine> <param> [--verbose]
OR
{0} --help

\033[1mEXAMPLES:\033[0m
    \033[1;32m# Query machine 'mappy' for parameter 'DIN_LOC_ROOT' \033[0m
    > {0} mappy DIN_LOC_ROOT
""".format(pathlib.Path(args[0]).name),
        description=description,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument("machine", help="The name of the machine")

    parser.add_argument("param", help="The name of the parameter being queried")

    return parser.parse_args(args[1:])

###############################################################################
def _main_func(description):
###############################################################################
    print(query_cime(**vars(parse_command_line(sys.argv, description))))

###############################################################################

if (__name__ == "__main__"):
    _main_func(__doc__)
