~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# TODO: For things like --diff-prefix, we want a way to customize the display
18
18
# of the option argument.
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import optparse
21
23
import re
22
24
 
25
27
from bzrlib import (
26
28
    errors,
27
29
    revisionspec,
 
30
    i18n,
28
31
    )
29
32
""")
30
33
 
331
334
        :param short_name: The short name for the enum switch, if any
332
335
        :param short_value_switches: A dict mapping values to short names
333
336
        """
334
 
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
 
337
        Option.__init__(self, name, help, type=self.convert,
 
338
                        short_name=short_name)
335
339
        self._registry = registry
336
340
        if registry is None:
337
341
            if lazy_registry is None:
429
433
 
430
434
    DEFAULT_VALUE = object()
431
435
 
 
436
    def __init__(self):
 
437
        optparse.OptionParser.__init__(self)
 
438
        self.formatter = GettextIndentedHelpFormatter()
 
439
 
432
440
    def error(self, message):
433
441
        raise errors.BzrCommandError(message)
434
442
 
435
443
 
 
444
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
 
445
    """Adds gettext() call to format_option()"""
 
446
    def __init__(self):
 
447
        optparse.IndentedHelpFormatter.__init__(self)
 
448
 
 
449
    def format_option(self, option):
 
450
        """code taken from Python's optparse.py"""
 
451
        if option.help:
 
452
            option.help = i18n.gettext(option.help)
 
453
        return optparse.IndentedHelpFormatter.format_option(self, option)
 
454
 
 
455
 
436
456
def get_optparser(options):
437
457
    """Generate an optparse parser for bzrlib-style options"""
438
458
 
457
477
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
458
478
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
459
479
 
 
480
def _standard_list_option(name, **kwargs):
 
481
    """Register a standard option."""
 
482
    # All standard options are implicitly 'global' ones
 
483
    Option.STD_OPTIONS[name] = ListOption(name, **kwargs)
 
484
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
 
485
 
460
486
 
461
487
def _global_option(name, **kwargs):
462
488
    """Register a global option."""
495
521
            _verbosity_level = -1
496
522
 
497
523
 
498
 
class MergeTypeRegistry(_mod_registry.Registry):
499
 
 
500
 
    pass
501
 
 
502
 
 
503
 
_merge_type_registry = MergeTypeRegistry()
504
 
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
505
 
                                   "Native diff3-style merge")
506
 
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
507
 
                                   "Merge using external diff3")
508
 
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
509
 
                                   "Weave-based merge")
510
 
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
511
 
                                   "LCA-newness merge")
512
 
 
513
524
# Declare the standard options
514
525
_standard_option('help', short_name='h',
515
526
                 help='Show help message.')
 
527
_standard_option('quiet', short_name='q',
 
528
                 help="Only display errors and warnings.",
 
529
                 custom_callback=_verbosity_level_callback)
516
530
_standard_option('usage',
517
531
                 help='Show usage message and options.')
518
532
_standard_option('verbose', short_name='v',
519
533
                 help='Display more information.',
520
534
                 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
535
 
525
536
# Declare commonly used options
526
 
_global_option('all')
527
 
_global_option('overwrite', help='Ignore differences between branches and '
528
 
               'overwrite unconditionally.')
529
 
_global_option('basis', type=str)
530
 
_global_option('bound')
531
 
_global_option('diff-options', type=str)
 
537
_global_option('change',
 
538
               type=_parse_change_str,
 
539
               short_name='c',
 
540
               param_name='revision',
 
541
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
 
542
_global_option('directory', short_name='d', type=unicode,
 
543
               help='Branch to operate on, instead of working directory.')
532
544
_global_option('file', type=unicode, short_name='F')
533
 
_global_option('force')
534
 
_global_option('format', type=unicode)
535
 
_global_option('forward')
 
545
_global_registry_option('log-format', "Use specified log format.",
 
546
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
 
547
                        value_switches=True, title='Log format',
 
548
                        short_value_switches={'short': 'S'})
 
549
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
 
550
                        lazy_registry=('bzrlib.merge', 'merge_type_registry'),
 
551
                        value_switches=True, title='Merge algorithm')
536
552
_global_option('message', type=unicode,
537
553
               short_name='m',
538
554
               help='Message string.')
539
 
_global_option('no-recurse')
540
555
_global_option('null', short_name='0',
541
556
                 help='Use an ASCII NUL (\\0) separator rather than '
542
557
                      'a newline.')
543
 
_global_option('profile',
544
 
               help='Show performance profiling information.')
 
558
_global_option('overwrite', help='Ignore differences between branches and '
 
559
               'overwrite unconditionally.')
 
560
_global_option('remember', help='Remember the specified location as a'
 
561
               ' default.')
 
562
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
545
563
_global_option('revision',
546
564
               type=_parse_revision_str,
547
565
               short_name='r',
548
566
               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".')
554
567
_global_option('show-ids',
555
568
               help='Show internal object ids.')
556
569
_global_option('timezone',
557
570
               type=str,
558
571
               help='Display timezone as local, original, or utc.')
559
 
_global_option('unbound')
560
 
_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
572
 
587
573
diff_writer_registry = _mod_registry.Registry()
588
574
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')