~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Aaron Bentley
  • Date: 2007-03-02 04:53:10 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: aaron.bentley@utoronto.ca-20070302045310-a4jr2qd18xuzqz25
Allow RegistryOption to omit the value-taking option

Show diffs side-by-side

added added

removed removed

Lines of Context:
227
227
            return self.converter(value)
228
228
 
229
229
    def __init__(self, name, help, registry, converter=None,
230
 
        value_switches=False, title=None):
 
230
        value_switches=False, title=None, enum_switch=True):
231
231
        """
232
232
        Constructor.
233
233
 
239
239
        :param value_switches: If true, each possible value is assigned its
240
240
            own switch.  For example, instead of '--format knit',
241
241
            '--knit' can be used interchangeably.
 
242
        :param enum_switch: If true, a switch is provided with the option name,
 
243
            which takes a value.
242
244
        """
243
245
        Option.__init__(self, name, help, type=self.convert)
244
246
        self.registry = registry
245
247
        self.name = name
246
248
        self.converter = converter
247
249
        self.value_switches = value_switches
 
250
        self.enum_switch = enum_switch
248
251
        self.title = title
249
252
        if self.title is None:
250
253
            self.title = name
253
256
        """Add this option to an Optparse parser"""
254
257
        if self.value_switches:
255
258
            parser = parser.add_option_group(self.title)
256
 
        Option.add_option(self, parser, short_name)
 
259
        if self.enum_switch:
 
260
            Option.add_option(self, parser, short_name)
257
261
        if self.value_switches:
258
262
            for key in self.registry.keys():
259
263
                option_strings = ['--%s' % key]