~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

(robertc) Fix lp: urls behind an https proxy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib import (
26
26
    errors,
27
27
    revisionspec,
28
 
    i18n,
29
28
    )
30
29
""")
31
30
 
313
312
 
314
313
    def __init__(self, name, help, registry=None, converter=None,
315
314
        value_switches=False, title=None, enum_switch=True,
316
 
        lazy_registry=None, short_name=None, short_value_switches=None):
 
315
        lazy_registry=None):
317
316
        """
318
317
        Constructor.
319
318
 
329
328
            which takes a value.
330
329
        :param lazy_registry: A tuple of (module name, attribute name) for a
331
330
            registry to be lazily loaded.
332
 
        :param short_name: The short name for the enum switch, if any
333
 
        :param short_value_switches: A dict mapping values to short names
334
331
        """
335
 
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
 
332
        Option.__init__(self, name, help, type=self.convert)
336
333
        self._registry = registry
337
334
        if registry is None:
338
335
            if lazy_registry is None:
347
344
        self.converter = converter
348
345
        self.value_switches = value_switches
349
346
        self.enum_switch = enum_switch
350
 
        self.short_value_switches = short_value_switches
351
347
        self.title = title
352
348
        if self.title is None:
353
349
            self.title = name
391
387
                    help = optparse.SUPPRESS_HELP
392
388
                else:
393
389
                    help = self.registry.get_help(key)
394
 
                if (self.short_value_switches and
395
 
                    key in self.short_value_switches):
396
 
                    option_strings.append('-%s' %
397
 
                                          self.short_value_switches[key])
398
390
                parser.add_option(action='callback',
399
391
                              callback=self._optparse_value_callback(key),
400
392
                                  help=help,
430
422
 
431
423
    DEFAULT_VALUE = object()
432
424
 
433
 
    def __init__(self):
434
 
        optparse.OptionParser.__init__(self)
435
 
        self.formatter = GettextIndentedHelpFormatter()
436
 
 
437
425
    def error(self, message):
438
426
        raise errors.BzrCommandError(message)
439
427
 
440
 
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
441
 
    """Adds gettext() call to format_option()"""
442
 
    def __init__(self):
443
 
        optparse.IndentedHelpFormatter.__init__(self)
444
 
 
445
 
    def format_option(self, option):
446
 
        """code taken from Python's optparse.py"""
447
 
        if option.help:
448
 
            option.help = i18n.gettext(option.help)
449
 
        return optparse.IndentedHelpFormatter.format_option(self, option)
450
428
 
451
429
def get_optparser(options):
452
430
    """Generate an optparse parser for bzrlib-style options"""
528
506
# Declare the standard options
529
507
_standard_option('help', short_name='h',
530
508
                 help='Show help message.')
 
509
_standard_option('null', short_name='0',
 
510
                 help='Use an ASCII NUL (\\0) separator rather than '
 
511
                      'a newline.')
531
512
_standard_option('usage',
532
513
                 help='Show usage message and options.')
533
514
_standard_option('verbose', short_name='v',
552
533
               short_name='m',
553
534
               help='Message string.')
554
535
_global_option('no-recurse')
555
 
_global_option('null', short_name='0',
556
 
                 help='Use an ASCII NUL (\\0) separator rather than '
557
 
                      'a newline.')
558
536
_global_option('profile',
559
537
               help='Show performance profiling information.')
560
538
_global_option('revision',
577
555
_global_option('update')
578
556
_global_registry_option('log-format', "Use specified log format.",
579
557
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
580
 
                        value_switches=True, title='Log format',
581
 
                        short_value_switches={'short': 'S'})
 
558
                        value_switches=True, title='Log format')
582
559
_global_option('long', help='Use detailed log format. Same as --log-format long',
583
560
               short_name='l')
584
561
_global_option('short', help='Use moderately short log format. Same as --log-format short')