def options(option_list, arg_desc="arg"):
    if not isinstance(option_list, list):
        option_list = [option_list]
    for opt in option_list:
        options_defined.append(pyparsing.Literal(opt.get_opt_string()))
    def option_setup(func):
        optionParser = OptionParser()
        for opt in option_list:
            optionParser.add_option(opt)
        optionParser.set_usage("%s [options] %s" % (func.__name__[3:], arg_desc))
        optionParser._func = func
        def new_func(instance, arg):
            try:
                opts, newArgList = optionParser.parse_args(arg.split())
                newArgs = remaining_args(arg, newArgList)
                arg = newArgs
            except optparse.OptParseError as e:
                instance.sendData(str(e))
                return instance.sendData(optionParser.format_help())
            return func(instance, arg, opts)
        new_func.__doc__ = func.__doc__
        new_func.__extended_doc__ = optionParser.format_help()
        return new_func
    return option_setup
Used as a decorator and passed a list of optparse-style options,
dataset/ETHPy150Open jookies/jasmin/jasmin/protocols/cli/options.py/options