My Python script (for todo lists) is run from the command line as follows:
todo [options] <command> [command-options]
Some parameters cannot be used together, for example
todo add --pos=3 --end "Ask Stackoverflow"
will indicate both the third position and the end of the list. Similarly
todo list --brief --informative
will confuse my program about being concise or informative. Since I want to have quite powerful control over the parameters, such cases will be a bunch, and new ones will undoubtedly arise in the future. If users pass a poor combination of parameters, I want to give an informative message, preferably together with the help provided by optparse. I am currently processing this with an if-else statement, which I find very ugly and poor. My dream is to have something like this in my code:
parser.set_not_allowed(combination=["--pos", "--end"], message="--pos and --end can not be used together")
and OptionParser will use this when parsing the parameters.
Since this does not exist, as far as I know, I ask the SO community: How do you deal with this?
python optparse
Joel
source share