def parse_args()

in lib/muchos/util.py [0:0]


def parse_args(hosts_dir, input_args=None):
    parser = OptionParser(
        usage="muchos [options] <action>\n\n"
        + "where <action> can be:\n"
        + "  launch           Launch cluster in Azure or EC2\n"
        + "  status           Check status of Azure or EC2 cluster\n"
        + "  setup            Set up cluster\n"
        + "  sync             Sync ansible directory on cluster proxy node\n"
        + "  config           Print configuration for that cluster. "
        "Requires '-p'. Use '-p all' for all config.\n"
        + "  stop             Stops instance\n"
        + "  start            Starts instance\n"
        + "  ssh              SSH to cluster proxy node\n"
        + "  kill             Kills processes on cluster started by Muchos\n"
        + "  wipe             Wipes cluster data and kills processes\n"
        + "  terminate        Terminate EC2 cluster\n"
        + "  cancel_shutdown  Cancels automatic shutdown of EC2 cluster",
        add_help_option=False,
    )
    parser.add_option(
        "-c", "--cluster", dest="cluster", help="Specifies cluster"
    )
    parser.add_option(
        "-p",
        "--property",
        dest="property",
        help="Specifies property to print (if using 'config' action)"
        ". Set to 'all' to print every property",
    )
    parser.add_option(
        "-h", "--help", action="help", help="Show this help message and exit"
    )

    if input_args:
        (opts, args) = parser.parse_args(input_args)
    else:
        (opts, args) = parser.parse_args()

    if len(args) == 0:
        print("ERROR - You must specify on action")
        return
    action = args[0]

    if action == "launch" and not opts.cluster:
        print("ERROR - You must specify a cluster if using launch command")
        return

    clusters = [f for f in os.listdir(hosts_dir) if isfile(join(hosts_dir, f))]

    if not opts.cluster:
        if len(clusters) == 0:
            print(
                "ERROR - No clusters found in conf/hosts "
                "or specified by --cluster option"
            )
            return
        elif len(clusters) == 1:
            opts.cluster = clusters[0]
        else:
            print(
                "ERROR - Multiple clusters {0} found in conf/hosts/. "
                "Please pick one using --cluster option".format(clusters)
            )
            return

    if action == "config" and not opts.property:
        print(
            "ERROR - For config action, you must set -p to a property or 'all'"
        )
        return

    return opts, action, args[1:]