argparse上的抽象层。
caipyrinha的Python项目详细描述
argparse上的抽象层。
caipyrinha向argparse.argumentparser添加了2个方法,callback和 parse_wc。caipyrinha实例也是可调用的,并且等于使用 parse_wc方法。
使用示例:
# ex.pyimportcaipyrinhaparser=caipyrinha.Caipyrinha(prog="Your Program")parser.add_argument("--version",action='version',version="%(prog)s 0.1")@parser.callback(exit=0,exclusive="group1")deffirst(flags,returns):'''Execute this option and exit'''print"bye bye"@parser.callback(action="store")defsecond(flags,returns):'''set his own return value with his parameter'''returnflags.second@parser.callback("--third",exclusive="group1")defno_used_name(flags,returns):'''you cant use this argument with first'''printreturns.secondimportsysparser(sys.argv[1:])
用法
$ python ex.py --help usage: Your Program [-h] [--version] [--first] [--second SECOND] [--third] optional arguments: -h, --help show this help message and exit --version show program's version number and exit --first Execute this option and exit --second SECOND set his own return value with his parameter --third you cant use this argument with first $ python ex.py --first bye bye $ python ex.py --first --second "hello from second" bye bye $ python ex.py --first --second "hello from second" --third usage: Your Program [-h] [--version] [--first] [--second SECOND] [--third] Your Program: error: argument --third: not allowed with argument --first $ python ex.py --second "hello from second" --third hello from second