~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Launchpad Translations on behalf of bzr-core
  • Date: 2012-07-21 04:30:31 UTC
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: launchpad_translations_on_behalf_of_bzr-core-20120721043031-pjhomz88j0qw381z
Launchpad automatic translations update.

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