2003-01-06 12:51:37 -04:00
|
|
|
import optparse
|
|
|
|
|
|
|
|
class OptionParser (optparse.OptionParser):
|
|
|
|
|
|
|
|
def check_required (self, opt):
|
2004-07-18 03:25:50 -03:00
|
|
|
option = self.get_option(opt)
|
2003-01-06 12:51:37 -04:00
|
|
|
|
2004-07-18 03:25:50 -03:00
|
|
|
# Assumes the option's 'default' is set to None!
|
|
|
|
if getattr(self.values, option.dest) is None:
|
|
|
|
self.error("%s option not supplied" % option)
|
2003-01-06 12:51:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("-v", action="count", dest="verbose")
|
|
|
|
parser.add_option("-f", "--file", default=None)
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
print "verbose:", options.verbose
|
|
|
|
print "file:", options.file
|
|
|
|
parser.check_required("-f")
|