~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Andrew Bennetts
  • Date: 2010-07-29 11:17:57 UTC
  • mfrom: (5050.3.17 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100729111757-018h3pcefo7z0dnq
Merge lp:bzr/2.2 into lp:bzr.

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,
336
 
                        short_name=short_name)
 
332
        Option.__init__(self, name, help, type=self.convert)
337
333
        self._registry = registry
338
334
        if registry is None:
339
335
            if lazy_registry is None:
348
344
        self.converter = converter
349
345
        self.value_switches = value_switches
350
346
        self.enum_switch = enum_switch
351
 
        self.short_value_switches = short_value_switches
352
347
        self.title = title
353
348
        if self.title is None:
354
349
            self.title = name
392
387
                    help = optparse.SUPPRESS_HELP
393
388
                else:
394
389
                    help = self.registry.get_help(key)
395
 
                if (self.short_value_switches and
396
 
                    key in self.short_value_switches):
397
 
                    option_strings.append('-%s' %
398
 
                                          self.short_value_switches[key])
399
390
                parser.add_option(action='callback',
400
391
                              callback=self._optparse_value_callback(key),
401
392
                                  help=help,
431
422
 
432
423
    DEFAULT_VALUE = object()
433
424
 
434
 
    def __init__(self):
435
 
        optparse.OptionParser.__init__(self)
436
 
        self.formatter = GettextIndentedHelpFormatter()
437
 
 
438
425
    def error(self, message):
439
426
        raise errors.BzrCommandError(message)
440
427
 
441
428
 
442
 
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
443
 
    """Adds gettext() call to format_option()"""
444
 
    def __init__(self):
445
 
        optparse.IndentedHelpFormatter.__init__(self)
446
 
 
447
 
    def format_option(self, option):
448
 
        """code taken from Python's optparse.py"""
449
 
        if option.help:
450
 
            option.help = i18n.gettext(option.help)
451
 
        return optparse.IndentedHelpFormatter.format_option(self, option)
452
 
 
453
 
 
454
429
def get_optparser(options):
455
430
    """Generate an optparse parser for bzrlib-style options"""
456
431
 
475
450
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
476
451
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
477
452
 
478
 
def _standard_list_option(name, **kwargs):
479
 
    """Register a standard option."""
480
 
    # All standard options are implicitly 'global' ones
481
 
    Option.STD_OPTIONS[name] = ListOption(name, **kwargs)
482
 
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
483
 
 
484
453
 
485
454
def _global_option(name, **kwargs):
486
455
    """Register a global option."""
525
494
 
526
495
 
527
496
_merge_type_registry = MergeTypeRegistry()
 
497
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
 
498
                                   "Native diff3-style merge")
528
499
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
529
500
                                   "Merge using external diff3")
 
501
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
 
502
                                   "Weave-based merge")
530
503
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
531
504
                                   "LCA-newness merge")
532
 
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
533
 
                                   "Native diff3-style merge")
534
 
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
535
 
                                   "Weave-based merge")
536
505
 
537
506
# Declare the standard options
538
507
_standard_option('help', short_name='h',
539
508
                 help='Show help message.')
540
 
_standard_option('quiet', short_name='q',
541
 
                 help="Only display errors and warnings.",
542
 
                 custom_callback=_verbosity_level_callback)
543
509
_standard_option('usage',
544
510
                 help='Show usage message and options.')
545
511
_standard_option('verbose', short_name='v',
546
512
                 help='Display more information.',
547
513
                 custom_callback=_verbosity_level_callback)
 
514
_standard_option('quiet', short_name='q',
 
515
                 help="Only display errors and warnings.",
 
516
                 custom_callback=_verbosity_level_callback)
548
517
 
549
518
# Declare commonly used options
550
519
_global_option('all')
 
520
_global_option('overwrite', help='Ignore differences between branches and '
 
521
               'overwrite unconditionally.')
551
522
_global_option('basis', type=str)
552
523
_global_option('bound')
553
 
_global_option('change',
554
 
               type=_parse_change_str,
555
 
               short_name='c',
556
 
               param_name='revision',
557
 
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
558
524
_global_option('diff-options', type=str)
559
 
_global_option('directory', short_name='d', type=unicode,
560
 
               help='Branch to operate on, instead of working directory')
561
 
_global_option('dry-run',
562
 
               help="Show what would be done, but don't actually do anything.")
563
 
_global_option('email')
564
525
_global_option('file', type=unicode, short_name='F')
565
526
_global_option('force')
566
527
_global_option('format', type=unicode)
567
528
_global_option('forward')
568
 
_global_option('kind', type=str)
569
 
_global_option('line', help='Use log format with one line per revision.'
570
 
               ' Same as --log-format line')
571
 
_global_registry_option('log-format', "Use specified log format.",
572
 
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
573
 
                        value_switches=True, title='Log format',
574
 
                        short_value_switches={'short': 'S'})
575
 
_global_option('long', help='Use detailed log format.'
576
 
               ' Same as --log-format long',
577
 
               short_name='l')
578
 
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
579
 
                        _merge_type_registry, value_switches=True,
580
 
                        title='Merge algorithm')
581
529
_global_option('message', type=unicode,
582
530
               short_name='m',
583
531
               help='Message string.')
584
 
_global_option('name-from-revision', help='The path name in the old tree.')
585
 
_global_option('no-backup')
586
532
_global_option('no-recurse')
587
533
_global_option('null', short_name='0',
588
534
                 help='Use an ASCII NUL (\\0) separator rather than '
589
535
                      'a newline.')
590
 
_global_option('overwrite', help='Ignore differences between branches and '
591
 
               'overwrite unconditionally.')
592
 
_global_option('pattern', type=str)
593
536
_global_option('profile',
594
537
               help='Show performance profiling information.')
595
 
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
596
 
_global_option('remember', help='Remember the specified location as a'
597
 
               ' default.')
598
538
_global_option('revision',
599
539
               type=_parse_revision_str,
600
540
               short_name='r',
601
541
               help='See "help revisionspec" for details.')
602
 
_global_option('short', help='Use moderately short log format.'
603
 
               ' Same as --log-format short')
 
542
_global_option('change',
 
543
               type=_parse_change_str,
 
544
               short_name='c',
 
545
               param_name='revision',
 
546
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
604
547
_global_option('show-ids',
605
548
               help='Show internal object ids.')
606
549
_global_option('timezone',
607
550
               type=str,
608
551
               help='Display timezone as local, original, or utc.')
609
 
_global_option('root', type=str)
610
552
_global_option('unbound')
 
553
_global_option('version')
 
554
_global_option('email')
611
555
_global_option('update')
612
 
_global_option('version')
 
556
_global_registry_option('log-format', "Use specified log format.",
 
557
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
 
558
                        value_switches=True, title='Log format')
 
559
_global_option('long', help='Use detailed log format. Same as --log-format long',
 
560
               short_name='l')
 
561
_global_option('short', help='Use moderately short log format. Same as --log-format short')
 
562
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
 
563
_global_option('root', type=str)
 
564
_global_option('no-backup')
 
565
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
 
566
                        _merge_type_registry, value_switches=True,
 
567
                        title='Merge algorithm')
 
568
_global_option('pattern', type=str)
 
569
_global_option('remember', help='Remember the specified location as a'
 
570
               ' default.')
 
571
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
 
572
_global_option('kind', type=str)
 
573
_global_option('dry-run',
 
574
               help="Show what would be done, but don't actually do anything.")
 
575
_global_option('name-from-revision', help='The path name in the old tree.')
 
576
_global_option('directory', short_name='d', type=unicode,
 
577
               help='Branch to operate on, instead of working directory')
613
578
 
614
579
diff_writer_registry = _mod_registry.Registry()
615
580
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')