~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-09 13:52:06 UTC
  • mfrom: (6202.1.3 revno-revision)
  • Revision ID: pqm@pqm.ubuntu.com-20111009135206-t3utsln6mtzv9eut
(jelmer) Add a --revision argument to 'bzr revno'. (Jelmer Vernooij)

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,
28
29
    )
29
30
""")
30
31
 
331
332
        :param short_name: The short name for the enum switch, if any
332
333
        :param short_value_switches: A dict mapping values to short names
333
334
        """
334
 
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
 
335
        Option.__init__(self, name, help, type=self.convert,
 
336
                        short_name=short_name)
335
337
        self._registry = registry
336
338
        if registry is None:
337
339
            if lazy_registry is None:
429
431
 
430
432
    DEFAULT_VALUE = object()
431
433
 
 
434
    def __init__(self):
 
435
        optparse.OptionParser.__init__(self)
 
436
        self.formatter = GettextIndentedHelpFormatter()
 
437
 
432
438
    def error(self, message):
433
439
        raise errors.BzrCommandError(message)
434
440
 
435
441
 
 
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
 
436
454
def get_optparser(options):
437
455
    """Generate an optparse parser for bzrlib-style options"""
438
456
 
457
475
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
458
476
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
459
477
 
 
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
 
460
484
 
461
485
def _global_option(name, **kwargs):
462
486
    """Register a global option."""
501
525
 
502
526
 
503
527
_merge_type_registry = MergeTypeRegistry()
 
528
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
 
529
                                   "Merge using external diff3")
 
530
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
 
531
                                   "LCA-newness merge")
504
532
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
505
533
                                   "Native diff3-style merge")
506
 
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
507
 
                                   "Merge using external diff3")
508
534
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
509
535
                                   "Weave-based merge")
510
 
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
511
 
                                   "LCA-newness merge")
512
536
 
513
537
# Declare the standard options
514
538
_standard_option('help', short_name='h',
515
539
                 help='Show help message.')
 
540
_standard_option('quiet', short_name='q',
 
541
                 help="Only display errors and warnings.",
 
542
                 custom_callback=_verbosity_level_callback)
516
543
_standard_option('usage',
517
544
                 help='Show usage message and options.')
518
545
_standard_option('verbose', short_name='v',
519
546
                 help='Display more information.',
520
547
                 custom_callback=_verbosity_level_callback)
521
 
_standard_option('quiet', short_name='q',
522
 
                 help="Only display errors and warnings.",
523
 
                 custom_callback=_verbosity_level_callback)
524
548
 
525
549
# Declare commonly used options
526
550
_global_option('all')
527
 
_global_option('overwrite', help='Ignore differences between branches and '
528
 
               'overwrite unconditionally.')
529
551
_global_option('basis', type=str)
530
552
_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".')
531
558
_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')
532
564
_global_option('file', type=unicode, short_name='F')
533
565
_global_option('force')
534
566
_global_option('format', type=unicode)
535
567
_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')
536
581
_global_option('message', type=unicode,
537
582
               short_name='m',
538
583
               help='Message string.')
 
584
_global_option('name-from-revision', help='The path name in the old tree.')
 
585
_global_option('no-backup')
539
586
_global_option('no-recurse')
540
587
_global_option('null', short_name='0',
541
588
                 help='Use an ASCII NUL (\\0) separator rather than '
542
589
                      'a newline.')
 
590
_global_option('overwrite', help='Ignore differences between branches and '
 
591
               'overwrite unconditionally.')
 
592
_global_option('pattern', type=str)
543
593
_global_option('profile',
544
594
               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.')
545
598
_global_option('revision',
546
599
               type=_parse_revision_str,
547
600
               short_name='r',
548
601
               help='See "help revisionspec" for details.')
549
 
_global_option('change',
550
 
               type=_parse_change_str,
551
 
               short_name='c',
552
 
               param_name='revision',
553
 
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
 
602
_global_option('short', help='Use moderately short log format.'
 
603
               ' Same as --log-format short')
554
604
_global_option('show-ids',
555
605
               help='Show internal object ids.')
556
606
_global_option('timezone',
557
607
               type=str,
558
608
               help='Display timezone as local, original, or utc.')
 
609
_global_option('root', type=str)
559
610
_global_option('unbound')
 
611
_global_option('update')
560
612
_global_option('version')
561
 
_global_option('email')
562
 
_global_option('update')
563
 
_global_registry_option('log-format', "Use specified log format.",
564
 
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
565
 
                        value_switches=True, title='Log format',
566
 
                        short_value_switches={'short': 'S'})
567
 
_global_option('long', help='Use detailed log format. Same as --log-format long',
568
 
               short_name='l')
569
 
_global_option('short', help='Use moderately short log format. Same as --log-format short')
570
 
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
571
 
_global_option('root', type=str)
572
 
_global_option('no-backup')
573
 
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
574
 
                        _merge_type_registry, value_switches=True,
575
 
                        title='Merge algorithm')
576
 
_global_option('pattern', type=str)
577
 
_global_option('remember', help='Remember the specified location as a'
578
 
               ' default.')
579
 
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
580
 
_global_option('kind', type=str)
581
 
_global_option('dry-run',
582
 
               help="Show what would be done, but don't actually do anything.")
583
 
_global_option('name-from-revision', help='The path name in the old tree.')
584
 
_global_option('directory', short_name='d', type=unicode,
585
 
               help='Branch to operate on, instead of working directory')
586
613
 
587
614
diff_writer_registry = _mod_registry.Registry()
588
615
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')