~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 08:40:16 UTC
  • mfrom: (5642.4.6 712474-module-available)
  • Revision ID: pqm@pqm.ubuntu.com-20110817084016-600z65qzqmmt44w7
(vila) ModuleAvailableFeature don't try to imported already imported
 modules. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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, default=[],
 
279
                          help=self.help, dest=self._param_name, 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):
 
315
        lazy_registry=None, short_name=None, short_value_switches=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
331
333
        """
332
 
        Option.__init__(self, name, help, type=self.convert)
 
334
        Option.__init__(self, name, help, type=self.convert, short_name=short_name)
333
335
        self._registry = registry
334
336
        if registry is None:
335
337
            if lazy_registry is None:
344
346
        self.converter = converter
345
347
        self.value_switches = value_switches
346
348
        self.enum_switch = enum_switch
 
349
        self.short_value_switches = short_value_switches
347
350
        self.title = title
348
351
        if self.title is None:
349
352
            self.title = name
364
367
        as values for the option, and their value is treated as the help.
365
368
        """
366
369
        reg = _mod_registry.Registry()
367
 
        for name, switch_help in kwargs.iteritems():
 
370
        for name, switch_help in sorted(kwargs.items()):
368
371
            name = name.replace('_', '-')
369
372
            reg.register(name, name, help=switch_help)
370
373
            if not value_switches:
387
390
                    help = optparse.SUPPRESS_HELP
388
391
                else:
389
392
                    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])
390
397
                parser.add_option(action='callback',
391
398
                              callback=self._optparse_value_callback(key),
392
399
                                  help=help,
530
537
               short_name='m',
531
538
               help='Message string.')
532
539
_global_option('no-recurse')
 
540
_global_option('null', short_name='0',
 
541
                 help='Use an ASCII NUL (\\0) separator rather than '
 
542
                      'a newline.')
533
543
_global_option('profile',
534
544
               help='Show performance profiling information.')
535
545
_global_option('revision',
552
562
_global_option('update')
553
563
_global_registry_option('log-format', "Use specified log format.",
554
564
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
555
 
                        value_switches=True, title='Log format')
 
565
                        value_switches=True, title='Log format',
 
566
                        short_value_switches={'short': 'S'})
556
567
_global_option('long', help='Use detailed log format. Same as --log-format long',
557
568
               short_name='l')
558
569
_global_option('short', help='Use moderately short log format. Same as --log-format short')
570
581
_global_option('dry-run',
571
582
               help="Show what would be done, but don't actually do anything.")
572
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')
573
586
 
574
587
diff_writer_registry = _mod_registry.Registry()
575
588
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')