205
205
yield self.name, self.short_name(), argname, self.help
208
class ListOption(Option):
209
"""Option used to provide a list of values.
211
On the command line, arguments are specified by a repeated use of the
212
option. '-' is a special argument that resets the list. For example,
214
sets the value of the 'foo' option to ['a', 'b'], and
215
--foo=a --foo=b --foo=- --foo=c
216
sets the value of the 'foo' option to ['c'].
219
def add_option(self, parser, short_name):
220
"""Add this option to an Optparse parser."""
221
option_strings = ['--%s' % self.name]
222
if short_name is not None:
223
option_strings.append('-%s' % short_name)
224
parser.add_option(action='callback',
225
callback=self._optparse_callback,
226
type='string', metavar=self.argname.upper(),
227
help=self.help, default=[],
230
def _optparse_callback(self, option, opt, value, parser):
231
values = getattr(parser.values, self.name)
235
values.append(self.type(value))
208
238
class RegistryOption(Option):
209
239
"""Option based on a registry