6.21.4.5 Callback example 2: check option order

Here's a slightly more interesting example: record the fact that "-a" is seen, but blow up if it comes after "-b" in the command-line.

def check_order(option, opt_str, value, parser):
 if parser.values.b:
 raise OptionValueError("can't use -a after -b")
 parser.values.a = 1
[...]
parser.add_option("-a", action="callback", callback=check_order)
parser.add_option("-b", action="store_true", dest="b")


Python Library Reference
Previous: Up: 6.21.4 Option Callbacks Next:

Release 2.4.4, documentation updated on 18 October 2006.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /