~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

(gz) Never raise KnownFailure in tests,
 use knownFailure method instead (Martin [gz])

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
 
332
331
        :param short_name: The short name for the enum switch, if any
333
332
        :param short_value_switches: A dict mapping values to short names
334
333
        """
335
 
        Option.__init__(self, name, help, type=self.convert,
336
 
                        short_name=short_name)
 
334
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
337
335
        self._registry = registry
338
336
        if registry is None:
339
337
            if lazy_registry is None:
431
429
 
432
430
    DEFAULT_VALUE = object()
433
431
 
434
 
    def __init__(self):
435
 
        optparse.OptionParser.__init__(self)
436
 
        self.formatter = GettextIndentedHelpFormatter()
437
 
 
438
432
    def error(self, message):
439
433
        raise errors.BzrCommandError(message)
440
434
 
441
435
 
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
436
def get_optparser(options):
455
437
    """Generate an optparse parser for bzrlib-style options"""
456
438
 
475
457
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
476
458
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
477
459
 
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
460
 
485
461
def _global_option(name, **kwargs):
486
462
    """Register a global option."""
519
495
            _verbosity_level = -1
520
496
 
521
497
 
 
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
 
522
513
# Declare the standard options
523
514
_standard_option('help', short_name='h',
524
515
                 help='Show help message.')
525
 
_standard_option('quiet', short_name='q',
526
 
                 help="Only display errors and warnings.",
527
 
                 custom_callback=_verbosity_level_callback)
528
516
_standard_option('usage',
529
517
                 help='Show usage message and options.')
530
518
_standard_option('verbose', short_name='v',
531
519
                 help='Display more information.',
532
520
                 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)
533
524
 
534
525
# Declare commonly used options
535
 
_global_option('change',
536
 
               type=_parse_change_str,
537
 
               short_name='c',
538
 
               param_name='revision',
539
 
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
540
 
_global_option('directory', short_name='d', type=unicode,
541
 
               help='Branch to operate on, instead of working directory.')
 
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)
542
532
_global_option('file', type=unicode, short_name='F')
543
 
_global_registry_option('log-format', "Use specified log format.",
544
 
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
545
 
                        value_switches=True, title='Log format',
546
 
                        short_value_switches={'short': 'S'})
547
 
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
548
 
                        lazy_registry=('bzrlib.merge', 'merge_type_registry'),
549
 
                        value_switches=True, title='Merge algorithm')
 
533
_global_option('force')
 
534
_global_option('format', type=unicode)
 
535
_global_option('forward')
550
536
_global_option('message', type=unicode,
551
537
               short_name='m',
552
538
               help='Message string.')
 
539
_global_option('no-recurse')
553
540
_global_option('null', short_name='0',
554
541
                 help='Use an ASCII NUL (\\0) separator rather than '
555
542
                      'a newline.')
556
 
_global_option('overwrite', help='Ignore differences between branches and '
557
 
               'overwrite unconditionally.')
558
 
_global_option('remember', help='Remember the specified location as a'
559
 
               ' default.')
560
 
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
 
543
_global_option('profile',
 
544
               help='Show performance profiling information.')
561
545
_global_option('revision',
562
546
               type=_parse_revision_str,
563
547
               short_name='r',
564
548
               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".')
565
554
_global_option('show-ids',
566
555
               help='Show internal object ids.')
567
556
_global_option('timezone',
568
557
               type=str,
569
558
               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')
570
586
 
571
587
diff_writer_registry = _mod_registry.Registry()
572
588
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')