~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Martin Pool
  • Date: 2010-01-29 14:09:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129140905-2uiarb6p8di1ywsr
Correction to url

from review: https://code.edge.launchpad.net/~mbp/bzr/doc/+merge/18250

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
276
276
        parser.add_option(action='callback',
277
277
                          callback=self._optparse_callback,
278
278
                          type='string', metavar=self.argname.upper(),
279
 
                          help=self.help, dest=self._param_name, default=[],
 
279
                          help=self.help, default=[],
280
280
                          *option_strings)
281
281
 
282
282
    def _optparse_callback(self, option, opt, value, parser):
312
312
 
313
313
    def __init__(self, name, help, registry=None, converter=None,
314
314
        value_switches=False, title=None, enum_switch=True,
315
 
        lazy_registry=None, short_name=None, short_value_switches=None):
 
315
        lazy_registry=None):
316
316
        """
317
317
        Constructor.
318
318
 
328
328
            which takes a value.
329
329
        :param lazy_registry: A tuple of (module name, attribute name) for a
330
330
            registry to be lazily loaded.
331
 
        :param short_name: The short name for the enum switch, if any
332
 
        :param short_value_switches: A dict mapping values to short names
333
331
        """
334
 
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
 
332
        Option.__init__(self, name, help, type=self.convert)
335
333
        self._registry = registry
336
334
        if registry is None:
337
335
            if lazy_registry is None:
346
344
        self.converter = converter
347
345
        self.value_switches = value_switches
348
346
        self.enum_switch = enum_switch
349
 
        self.short_value_switches = short_value_switches
350
347
        self.title = title
351
348
        if self.title is None:
352
349
            self.title = name
364
361
 
365
362
        name, help, value_switches and enum_switch are passed to the
366
363
        RegistryOption constructor.  Any other keyword arguments are treated
367
 
        as values for the option, and their value is treated as the help.
 
364
        as values for the option, and they value is treated as the help.
368
365
        """
369
366
        reg = _mod_registry.Registry()
370
 
        for name, switch_help in sorted(kwargs.items()):
 
367
        for name, switch_help in kwargs.iteritems():
371
368
            name = name.replace('_', '-')
372
369
            reg.register(name, name, help=switch_help)
373
370
            if not value_switches:
390
387
                    help = optparse.SUPPRESS_HELP
391
388
                else:
392
389
                    help = self.registry.get_help(key)
393
 
                if (self.short_value_switches and
394
 
                    key in self.short_value_switches):
395
 
                    option_strings.append('-%s' %
396
 
                                          self.short_value_switches[key])
397
390
                parser.add_option(action='callback',
398
391
                              callback=self._optparse_value_callback(key),
399
392
                                  help=help,
537
530
               short_name='m',
538
531
               help='Message string.')
539
532
_global_option('no-recurse')
540
 
_global_option('null', short_name='0',
541
 
                 help='Use an ASCII NUL (\\0) separator rather than '
542
 
                      'a newline.')
543
533
_global_option('profile',
544
534
               help='Show performance profiling information.')
545
535
_global_option('revision',
562
552
_global_option('update')
563
553
_global_registry_option('log-format', "Use specified log format.",
564
554
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
565
 
                        value_switches=True, title='Log format',
566
 
                        short_value_switches={'short': 'S'})
 
555
                        value_switches=True, title='Log format')
567
556
_global_option('long', help='Use detailed log format. Same as --log-format long',
568
557
               short_name='l')
569
558
_global_option('short', help='Use moderately short log format. Same as --log-format short')
581
570
_global_option('dry-run',
582
571
               help="Show what would be done, but don't actually do anything.")
583
572
_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
573
 
587
574
diff_writer_registry = _mod_registry.Registry()
588
575
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')