/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
        self.type = type
180
180
        self._short_name = short_name
181
181
        if type is None:
182
 
            assert argname is None
 
182
            if argname:
 
183
                raise ValueError('argname not valid for booleans')
183
184
        elif argname is None:
184
185
            argname = 'ARG'
185
186
        self.argname = argname
186
187
        if param_name is None:
187
 
            self._param_name = self.name
 
188
            self._param_name = self.name.replace('-', '_')
188
189
        else:
189
190
            self._param_name = param_name
190
191
        self.custom_callback = custom_callback
209
210
            option_strings.append('-%s' % short_name)
210
211
        optargfn = self.type
211
212
        if optargfn is None:
212
 
            parser.add_option(action='callback', 
213
 
                              callback=self._optparse_bool_callback, 
 
213
            parser.add_option(action='callback',
 
214
                              callback=self._optparse_bool_callback,
214
215
                              callback_args=(True,),
215
216
                              help=self.help,
216
217
                              *option_strings)
217
218
            negation_strings = ['--%s' % self.get_negation_name()]
218
 
            parser.add_option(action='callback', 
219
 
                              callback=self._optparse_bool_callback, 
 
219
            parser.add_option(action='callback',
 
220
                              callback=self._optparse_bool_callback,
220
221
                              callback_args=(False,),
221
222
                              help=optparse.SUPPRESS_HELP, *negation_strings)
222
223
        else:
223
 
            parser.add_option(action='callback', 
224
 
                              callback=self._optparse_callback, 
 
224
            parser.add_option(action='callback',
 
225
                              callback=self._optparse_callback,
225
226
                              type='string', metavar=self.argname.upper(),
226
227
                              help=self.help,
227
 
                              default=OptionParser.DEFAULT_VALUE, 
 
228
                              default=OptionParser.DEFAULT_VALUE,
228
229
                              *option_strings)
229
230
 
230
231
    def _optparse_bool_callback(self, option, opt_str, value, parser, bool_v):
359
360
        for name, switch_help in kwargs.iteritems():
360
361
            name = name.replace('_', '-')
361
362
            reg.register(name, name, help=switch_help)
 
363
            if not value_switches:
 
364
                help = help + '  "' + name + '": ' + switch_help
 
365
                if not help.endswith("."):
 
366
                    help = help + "."
362
367
        return RegistryOption(name_, help, reg, title=title,
363
368
            value_switches=value_switches, enum_switch=enum_switch)
364
369