import getopt


def get_command_line_args(argv):
    """
    Gets the command line arguments which are:

    Returns
    -------
    pm_model (str) - The PowerModels.jl power model e.g. "DCPPowerModel"
    pm_solver (str) - The solver to use, e.g. "juniper", "gurobi"
    grid_name (str) - optional if you only want to calculate one grid, e.g. "rts"
    lc (str) - the loadcases to calculate. Either "ts" or "scaled"
    kind (str) - the optimizations to run, e.g. "tnep,ots,repl". Can only be a part of these like "tnep,repl"

    """
    pm_model, pm_solver, grid_name = None, None, None
    kind = "tnep,repl,ots"
    lc = "scaled"
    try:
        opts, args = getopt.getopt(argv, ":m:s:g:k:",
                                   ["model=", "solver=", "grid=", "kind="])
    except getopt.GetoptError:
        raise getopt.GetoptError("error reading input")
    for opt, arg in opts:
        if opt in ("-m", "--model"):
            pm_model = arg
        if opt in ("-s", "--solver"):
            pm_solver = arg
        if opt in ("-g", "--grid"):
            grid_name = arg
        if opt in ("-k", "--kind"):
            kind = arg
    if pm_solver is None:
        UserWarning("pm_solver is None. You must specify a solver with '--solver='")
    if pm_model is None:
        UserWarning("pm_model is None. You must specify a model with '--model='")
    return pm_model, pm_solver, grid_name, lc, kind