/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

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        else:
204
204
            return 'no-' + self.name
205
205
 
206
 
    def add_option(self, parser, short_name):
 
206
    @staticmethod
 
207
    def get_gettext(l10n):
 
208
        """Returns the gettext function used to translate this Option's help.
 
209
 
 
210
        NOTE: Options provided by third party plugins should override this to
 
211
        use own i18n system.
 
212
        """
 
213
        if l10n:
 
214
            from bzrlib.i18n import gettext
 
215
            return gettext
 
216
        return lambda x: x
 
217
 
 
218
    def add_option(self, parser, short_name, l10n=False):
207
219
        """Add this option to an Optparse parser"""
 
220
        gettext = self.get_gettext(l10n)
208
221
        option_strings = ['--%s' % self.name]
209
222
        if short_name is not None:
210
223
            option_strings.append('-%s' % short_name)
211
224
        if self.hidden:
212
225
            help = optparse.SUPPRESS_HELP
213
226
        else:
214
 
            help = self.help
 
227
            help = gettext(self.help)
215
228
        optargfn = self.type
216
229
        if optargfn is None:
217
230
            parser.add_option(action='callback',
268
281
    sets the value of the 'foo' option to ['c'].
269
282
    """
270
283
 
271
 
    def add_option(self, parser, short_name):
 
284
    def add_option(self, parser, short_name, l10n=False):
272
285
        """Add this option to an Optparse parser."""
 
286
        gettext = self.get_gettext(l10n)
273
287
        option_strings = ['--%s' % self.name]
274
288
        if short_name is not None:
275
289
            option_strings.append('-%s' % short_name)
276
290
        parser.add_option(action='callback',
277
291
                          callback=self._optparse_callback,
278
292
                          type='string', metavar=self.argname.upper(),
279
 
                          help=self.help, dest=self._param_name, default=[],
280
 
                          *option_strings)
 
293
                          help=gettext(self.help), dest=self._param_name,
 
294
                          default=[], *option_strings)
281
295
 
282
296
    def _optparse_callback(self, option, opt, value, parser):
283
297
        values = getattr(parser.values, self._param_name)
312
326
 
313
327
    def __init__(self, name, help, registry=None, converter=None,
314
328
        value_switches=False, title=None, enum_switch=True,
315
 
        lazy_registry=None):
 
329
        lazy_registry=None, short_name=None):
316
330
        """
317
331
        Constructor.
318
332
 
329
343
        :param lazy_registry: A tuple of (module name, attribute name) for a
330
344
            registry to be lazily loaded.
331
345
        """
332
 
        Option.__init__(self, name, help, type=self.convert)
 
346
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
333
347
        self._registry = registry
334
348
        if registry is None:
335
349
            if lazy_registry is None:
374
388
        return RegistryOption(name_, help, reg, title=title,
375
389
            value_switches=value_switches, enum_switch=enum_switch)
376
390
 
377
 
    def add_option(self, parser, short_name):
 
391
    def add_option(self, parser, short_name, l10n=False):
378
392
        """Add this option to an Optparse parser"""
 
393
        gettext = self.get_gettext(l10n)
379
394
        if self.value_switches:
380
395
            parser = parser.add_option_group(self.title)
381
396
        if self.enum_switch:
386
401
                if self.is_hidden(key):
387
402
                    help = optparse.SUPPRESS_HELP
388
403
                else:
389
 
                    help = self.registry.get_help(key)
 
404
                    help = gettext(self.registry.get_help(key))
390
405
                parser.add_option(action='callback',
391
406
                              callback=self._optparse_value_callback(key),
392
407
                                  help=help,
426
441
        raise errors.BzrCommandError(message)
427
442
 
428
443
 
429
 
def get_optparser(options):
 
444
def get_optparser(options, l10n=False):
430
445
    """Generate an optparse parser for bzrlib-style options"""
431
446
 
432
447
    parser = OptionParser()
433
448
    parser.remove_option('--help')
434
449
    for option in options.itervalues():
435
 
        option.add_option(parser, option.short_name())
 
450
        option.add_option(parser, option.short_name(), l10n)
436
451
    return parser
437
452
 
438
453
 
530
545
               short_name='m',
531
546
               help='Message string.')
532
547
_global_option('no-recurse')
 
548
_global_option('null', short_name='0',
 
549
                 help='Use an ASCII NUL (\\0) separator rather than '
 
550
                      'a newline.')
533
551
_global_option('profile',
534
552
               help='Show performance profiling information.')
535
553
_global_option('revision',
570
588
_global_option('dry-run',
571
589
               help="Show what would be done, but don't actually do anything.")
572
590
_global_option('name-from-revision', help='The path name in the old tree.')
 
591
_global_option('directory', short_name='d', type=unicode,
 
592
               help='Branch to operate on, instead of working directory')
573
593
 
574
594
diff_writer_registry = _mod_registry.Registry()
575
595
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')