def parse_options():

    parser = OptionParser()

    parser.add_option("-c", "--config", dest="config",
            help="coil config file with test templates")
    parser.add_option("-v", "--loglevel", dest="loglevel",
            default="INFO", help="one of: ERROR WARN INFO DEBUG")
    parser.add_option("-l", "--logfile", dest="logfile",
            help="log file, automatically rotated")
    parser.add_option("-p", "--pidfile", dest="pidfile",
            help="pid file")
    parser.add_option("-d", "--daemon", dest="daemon",
            action="store_true", default=False,
            help="run as a daemon")
    parser.add_option("-n", "--nagios", dest="nagios",
            help="path to nagios.cfg (required)")
    parser.add_option("-P", "--port", dest="port", type="int",
            help="port to listen on (required)")
    parser.add_option("-H", "--host", dest="host", default="",
            help="local host name or address to listen on")
    parser.add_option("-R", "--read-only", action="store_true",
            help="provide information but don't accept commands")

    (options, args) = parser.parse_args()

    err = []
    if not options.nagios:
        err.append("--nagios is required")

    if not options.port:
        err.append("--port is required")

    if options.daemon and (not options.pidfile or not options.logfile):
        err.append("--logfile and --pidfile are required with --daemon")

    if options.loglevel not in log.LEVELS:
        err.append("invalid log level '%s'" % options.loglevel)
        err.append("must be one of: %s" % " ".join(log.LEVELS))

    if err:
        parser.error("\n".join(err))

    return options
Parse program options in sys.argv
dataset/ETHPy150Open marineam/nagcat/python/nagcat/nagnet.py/parse_options