FLAG = 1
PARAM = 2
INTPARAM = 3
+ PARAMLIST = 4
def __init__(self, cmd, remain_help, options):
self.options = options
shorts = ""
for opt in options:
long = self.long(opt)
short = self.short(opt)
- if self.type(opt) in (Options.PARAM, Options.INTPARAM):
- if short: short = short + ':'
- if long: long = long + '='
+ if self.type(opt) in (Options.PARAM, Options.INTPARAM,
+ Options.PARAMLIST):
+ if short: short = short + ':'
+ if long:
+ long = long + '='
+ if string.find(long, '_') >= 0:
+ longs.append(string.replace(long, '_', '-'))
shorts = shorts + short
longs.append(long)
self.short_opts = shorts
def default(self, option):
if len(option) >= 4:
return option[3]
+ if self.type(option) == Options.PARAMLIST:
+ return []
return None
def lookup_option(self, key, key_func):
return self.lookup_option(key, self.short)
def lookup_long(self, key):
+ key = string.replace(key, '-', '_')
return self.lookup_option(key, self.long)
def handle_opts(self, opts):
val = int(a)
except ValueError, e:
raise error.OptionError("option: '%s' expects integer value, got '%s' " % (o,a))
+ elif self.type(option) == Options.PARAMLIST:
+ val = values[self.key(option)];
+ val.append(a)
else:
val = 1
values[self.key(option)] = val
return self.values[name]
else:
raise error.OptionError("bad option name: " + name)
+ def __getitem__(self, name):
+ if self.values.has_key(name):
+ return self.values[name]
+ else:
+ raise error.OptionError("bad option name: " + name)
def __setattr__(self, name, value):
self.values[name] = value