~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

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
 
 
22
20
import optparse
23
21
import re
24
22
 
27
25
from bzrlib import (
28
26
    errors,
29
27
    revisionspec,
30
 
    i18n,
31
28
    )
32
29
""")
33
30
 
315
312
 
316
313
    def __init__(self, name, help, registry=None, converter=None,
317
314
        value_switches=False, title=None, enum_switch=True,
318
 
        lazy_registry=None, short_name=None, short_value_switches=None):
 
315
        lazy_registry=None):
319
316
        """
320
317
        Constructor.
321
318
 
331
328
            which takes a value.
332
329
        :param lazy_registry: A tuple of (module name, attribute name) for a
333
330
            registry to be lazily loaded.
334
 
        :param short_name: The short name for the enum switch, if any
335
 
        :param short_value_switches: A dict mapping values to short names
336
331
        """
337
 
        Option.__init__(self, name, help, type=self.convert,
338
 
                        short_name=short_name)
 
332
        Option.__init__(self, name, help, type=self.convert)
339
333
        self._registry = registry
340
334
        if registry is None:
341
335
            if lazy_registry is None:
350
344
        self.converter = converter
351
345
        self.value_switches = value_switches
352
346
        self.enum_switch = enum_switch
353
 
        self.short_value_switches = short_value_switches
354
347
        self.title = title
355
348
        if self.title is None:
356
349
            self.title = name
394
387
                    help = optparse.SUPPRESS_HELP
395
388
                else:
396
389
                    help = self.registry.get_help(key)
397
 
                if (self.short_value_switches and
398
 
                    key in self.short_value_switches):
399
 
                    option_strings.append('-%s' %
400
 
                                          self.short_value_switches[key])
401
390
                parser.add_option(action='callback',
402
391
                              callback=self._optparse_value_callback(key),
403
392
                                  help=help,
433
422
 
434
423
    DEFAULT_VALUE = object()
435
424
 
436
 
    def __init__(self):
437
 
        optparse.OptionParser.__init__(self)
438
 
        self.formatter = GettextIndentedHelpFormatter()
439
 
 
440
425
    def error(self, message):
441
426
        raise errors.BzrCommandError(message)
442
427
 
443
428
 
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
 
 
456
429
def get_optparser(options):
457
430
    """Generate an optparse parser for bzrlib-style options"""
458
431
 
477
450
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
478
451
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
479
452
 
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
 
 
486
453
 
487
454
def _global_option(name, **kwargs):
488
455
    """Register a global option."""
521
488
            _verbosity_level = -1
522
489
 
523
490
 
 
491
class MergeTypeRegistry(_mod_registry.Registry):
 
492
 
 
493
    pass
 
494
 
 
495
 
 
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',
 
502
                                   "Weave-based merge")
 
503
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
 
504
                                   "LCA-newness merge")
 
505
 
524
506
# Declare the standard options
525
507
_standard_option('help', short_name='h',
526
508
                 help='Show help message.')
527
 
_standard_option('quiet', short_name='q',
528
 
                 help="Only display errors and warnings.",
529
 
                 custom_callback=_verbosity_level_callback)
530
509
_standard_option('usage',
531
510
                 help='Show usage message and options.')
532
511
_standard_option('verbose', short_name='v',
533
512
                 help='Display more information.',
534
513
                 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)
535
517
 
536
518
# Declare commonly used options
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.')
 
519
_global_option('all')
 
520
_global_option('overwrite', help='Ignore differences between branches and '
 
521
               'overwrite unconditionally.')
 
522
_global_option('basis', type=str)
 
523
_global_option('bound')
 
524
_global_option('diff-options', type=str)
544
525
_global_option('file', type=unicode, short_name='F')
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')
 
526
_global_option('force')
 
527
_global_option('format', type=unicode)
 
528
_global_option('forward')
552
529
_global_option('message', type=unicode,
553
530
               short_name='m',
554
531
               help='Message string.')
 
532
_global_option('no-recurse')
555
533
_global_option('null', short_name='0',
556
534
                 help='Use an ASCII NUL (\\0) separator rather than '
557
535
                      'a newline.')
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.')
 
536
_global_option('profile',
 
537
               help='Show performance profiling information.')
563
538
_global_option('revision',
564
539
               type=_parse_revision_str,
565
540
               short_name='r',
566
541
               help='See "help revisionspec" for details.')
 
542
_global_option('change',
 
543
               type=_parse_change_str,
 
544
               short_name='c',
 
545
               param_name='revision',
 
546
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
567
547
_global_option('show-ids',
568
548
               help='Show internal object ids.')
569
549
_global_option('timezone',
570
550
               type=str,
571
551
               help='Display timezone as local, original, or utc.')
 
552
_global_option('unbound')
 
553
_global_option('version')
 
554
_global_option('email')
 
555
_global_option('update')
 
556
_global_registry_option('log-format', "Use specified log format.",
 
557
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
 
558
                        value_switches=True, title='Log format')
 
559
_global_option('long', help='Use detailed log format. Same as --log-format long',
 
560
               short_name='l')
 
561
_global_option('short', help='Use moderately short log format. Same as --log-format short')
 
562
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
 
563
_global_option('root', type=str)
 
564
_global_option('no-backup')
 
565
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
 
566
                        _merge_type_registry, value_switches=True,
 
567
                        title='Merge algorithm')
 
568
_global_option('pattern', type=str)
 
569
_global_option('remember', help='Remember the specified location as a'
 
570
               ' default.')
 
571
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
 
572
_global_option('kind', type=str)
 
573
_global_option('dry-run',
 
574
               help="Show what would be done, but don't actually do anything.")
 
575
_global_option('name-from-revision', help='The path name in the old tree.')
 
576
_global_option('directory', short_name='d', type=unicode,
 
577
               help='Branch to operate on, instead of working directory')
572
578
 
573
579
diff_writer_registry = _mod_registry.Registry()
574
580
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')