423
450
DEFAULT_VALUE = object()
453
optparse.OptionParser.__init__(self)
454
self.formatter = GettextIndentedHelpFormatter()
425
456
def error(self, message):
426
457
raise errors.BzrCommandError(message)
460
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
461
"""Adds gettext() call to format_option()"""
463
optparse.IndentedHelpFormatter.__init__(self)
465
def format_option(self, option):
466
"""code taken from Python's optparse.py"""
468
from .i18n import gettext
469
option.help = gettext(option.help)
470
return optparse.IndentedHelpFormatter.format_option(self, option)
429
473
def get_optparser(options):
430
"""Generate an optparse parser for bzrlib-style options"""
474
"""Generate an optparse parser for breezy-style options"""
432
476
parser = OptionParser()
433
477
parser.remove_option('--help')
434
for option in options.itervalues():
478
for option in options.values():
435
479
option.add_option(parser, option.short_name())
488
538
_verbosity_level = -1
491
class MergeTypeRegistry(_mod_registry.Registry):
496
_merge_type_registry = MergeTypeRegistry()
497
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
498
"Native diff3-style merge")
499
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
500
"Merge using external diff3")
501
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
503
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
506
541
# Declare the standard options
507
542
_standard_option('help', short_name='h',
508
543
help='Show help message.')
544
_standard_option('quiet', short_name='q',
545
help="Only display errors and warnings.",
546
custom_callback=_verbosity_level_callback)
509
547
_standard_option('usage',
510
548
help='Show usage message and options.')
511
549
_standard_option('verbose', short_name='v',
512
550
help='Display more information.',
513
551
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)
518
553
# Declare commonly used options
519
_global_option('all')
554
_global_option('change',
555
type=_parse_change_str,
557
param_name='revision',
558
help='Select changes introduced by the specified revision. See also "help revisionspec".')
559
_global_option('directory', short_name='d', type=text_type,
560
help='Branch to operate on, instead of working directory.')
561
_global_option('file', type=text_type, short_name='F')
562
_global_registry_option('log-format', "Use specified log format.",
563
lazy_registry=('breezy.log', 'log_formatter_registry'),
564
value_switches=True, title='Log format',
565
short_value_switches={'short': 'S'})
566
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
567
lazy_registry=('breezy.merge', 'merge_type_registry'),
568
value_switches=True, title='Merge algorithm')
569
_global_option('message', type=text_type,
571
help='Message string.')
572
_global_option('null', short_name='0',
573
help='Use an ASCII NUL (\\0) separator rather than '
520
575
_global_option('overwrite', help='Ignore differences between branches and '
521
576
'overwrite unconditionally.')
522
_global_option('basis', type=str)
523
_global_option('bound')
524
_global_option('diff-options', type=str)
525
_global_option('file', type=unicode, short_name='F')
526
_global_option('force')
527
_global_option('format', type=unicode)
528
_global_option('forward')
529
_global_option('message', type=unicode,
531
help='Message string.')
532
_global_option('no-recurse')
533
_global_option('profile',
534
help='Show performance profiling information.')
577
_global_option('remember', help='Remember the specified location as a'
579
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
535
580
_global_option('revision',
536
581
type=_parse_revision_str,
538
583
help='See "help revisionspec" for details.')
539
_global_option('change',
540
type=_parse_change_str,
542
param_name='revision',
543
help='Select changes introduced by the specified revision. See also "help revisionspec".')
544
584
_global_option('show-ids',
545
585
help='Show internal object ids.')
546
586
_global_option('timezone',
548
588
help='Display timezone as local, original, or utc.')
549
_global_option('unbound')
550
_global_option('version')
551
_global_option('email')
552
_global_option('update')
553
_global_registry_option('log-format', "Use specified log format.",
554
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
555
value_switches=True, title='Log format')
556
_global_option('long', help='Use detailed log format. Same as --log-format long',
558
_global_option('short', help='Use moderately short log format. Same as --log-format short')
559
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
560
_global_option('root', type=str)
561
_global_option('no-backup')
562
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
563
_merge_type_registry, value_switches=True,
564
title='Merge algorithm')
565
_global_option('pattern', type=str)
566
_global_option('remember', help='Remember the specified location as a'
568
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
569
_global_option('kind', type=str)
570
_global_option('dry-run',
571
help="Show what would be done, but don't actually do anything.")
572
_global_option('name-from-revision', help='The path name in the old tree.')
574
590
diff_writer_registry = _mod_registry.Registry()
575
591
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')