I want to make a bool arg into a store arg with presence on cli with no provided value as a legal setting:
prog.py [--nuke [name1[,name2]*]] # clean usual + optional csv string
eg
prog.py # no action
prog.py --nuke # usual clean
prog.py --nuke special,value # extra named clean csv value special
Realizing the simplest answer to this question is to have 2 options. But without stretching imagination too far, Id like to be very conservative with options.
I am trying to have empty parameter as a legal option. I presence of the parameter with no args is legal. Can I do this with a single parameter?
def pytest_addoption(parser):
parser.addoption('--nuke', action="store", default=False,
help="pass in named object to delete, or empty to "
"delete usual-suspects. eg. "
" prog --nuke # remove all but host"
" prog --nuke templates # all but host plus named vm")
Most familiar approach: make it 2 options instead of 1 --nuke(action=store_true); --doomed(action=append);
presence of 'nuke' implies do the default action. presence of 'doomed' implies modify nuke targets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.