0
我有一个CLI build.py
我把它叫做build.py -t -c -f
当我解析命令行参数的值,有一个内置的方式来获得的如何把列表中的多个命令行参数
['t' = true,'c'=true,'f'=true,'s'=false]
列表
下面是定义,不知道该怎么在dest
(即添加[..]
变化是行不通的。为了表明我怎么努力来实现的。
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-s","--stored_proc", dest="build_what['s']", action="store_true", help="build all stored procedures, or the folder/*.sql specified")
parser.add_argument("-t","--triggers", dest="build_what['t']", action="store_true", help="build all triggers, or the folder/*.sql specified")
parser.add_argument("-f","--functions", dest="build_what['f']", action="store_true", help="build all functions, or the folder/*.sql specified")
parser.add_argument("-c","--scripts", dest="build_what['c']", action="store_true", help="run all scripts, or the folder/*.sql specified")
你使用'argparse'吗? – Elisha 2014-10-02 16:13:09
已修改我正在使用ArgumentParser,从argparse导入ArgumentParser from argparse import RawDescriptionHelpFormatter – 2014-10-02 16:24:29
'['t'= true,'c'= true,'f'= true,'s'= false]'不是Python列表。你的意思是一本字典('{'t':true,'c':true,'f':true,'s':false}')? – isedev 2014-10-02 16:26:16