186
186
self.argname = argname
187
187
if param_name is None:
188
self._param_name = self.name
188
self._param_name = self.name.replace('-', '_')
190
190
self._param_name = param_name
191
191
self.custom_callback = custom_callback
210
210
option_strings.append('-%s' % short_name)
211
211
optargfn = self.type
212
212
if optargfn is None:
213
parser.add_option(action='callback',
214
callback=self._optparse_bool_callback,
213
parser.add_option(action='callback',
214
callback=self._optparse_bool_callback,
215
215
callback_args=(True,),
218
218
negation_strings = ['--%s' % self.get_negation_name()]
219
parser.add_option(action='callback',
220
callback=self._optparse_bool_callback,
219
parser.add_option(action='callback',
220
callback=self._optparse_bool_callback,
221
221
callback_args=(False,),
222
222
help=optparse.SUPPRESS_HELP, *negation_strings)
224
parser.add_option(action='callback',
225
callback=self._optparse_callback,
224
parser.add_option(action='callback',
225
callback=self._optparse_callback,
226
226
type='string', metavar=self.argname.upper(),
228
default=OptionParser.DEFAULT_VALUE,
228
default=OptionParser.DEFAULT_VALUE,
231
231
def _optparse_bool_callback(self, option, opt_str, value, parser, bool_v):
307
307
return self.converter(value)
309
def __init__(self, name, help, registry, converter=None,
310
value_switches=False, title=None, enum_switch=True):
309
def __init__(self, name, help, registry=None, converter=None,
310
value_switches=False, title=None, enum_switch=True,
321
322
'--knit' can be used interchangeably.
322
323
:param enum_switch: If true, a switch is provided with the option name,
323
324
which takes a value.
325
:param lazy_registry: A tuple of (module name, attribute name) for a
326
registry to be lazily loaded.
325
328
Option.__init__(self, name, help, type=self.convert)
326
self.registry = registry
329
self._registry = registry
331
if lazy_registry is None:
332
raise AssertionError(
333
'One of registry or lazy_registry must be given.')
334
self._lazy_registry = _mod_registry._LazyObjectGetter(
336
if registry is not None and lazy_registry is not None:
337
raise AssertionError(
338
'registry and lazy_registry are mutually exclusive')
328
340
self.converter = converter
329
341
self.value_switches = value_switches
332
344
if self.title is None:
333
345
self.title = name
349
if self._registry is None:
350
self._registry = self._lazy_registry.get_obj()
351
return self._registry
336
354
def from_kwargs(name_, help=None, title=None, value_switches=False,
337
355
enum_switch=True, **kwargs):
341
359
RegistryOption constructor. Any other keyword arguments are treated
342
360
as values for the option, and they value is treated as the help.
344
reg = registry.Registry()
362
reg = _mod_registry.Registry()
345
363
for name, switch_help in kwargs.iteritems():
346
364
name = name.replace('_', '-')
347
365
reg.register(name, name, help=switch_help)
366
if not value_switches:
367
help = help + ' "' + name + '": ' + switch_help
368
if not help.endswith("."):
348
370
return RegistryOption(name_, help, reg, title=title,
349
371
value_switches=value_switches, enum_switch=enum_switch)
430
452
Option.OPTIONS[name] = Option(name, **kwargs)
433
def _global_registry_option(name, help, registry, **kwargs):
455
def _global_registry_option(name, help, registry=None, **kwargs):
434
456
Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
437
class MergeTypeRegistry(registry.Registry):
442
459
# This is the verbosity level detected during command line parsing.
443
460
# Note that the final value is dependent on the order in which the
444
461
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
467
484
_verbosity_level = -1
487
class MergeTypeRegistry(_mod_registry.Registry):
470
492
_merge_type_registry = MergeTypeRegistry()
471
493
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
472
494
"Native diff3-style merge")
515
537
help='Select changes introduced by the specified revision. See also "help revisionspec".')
516
538
_global_option('show-ids',
517
539
help='Show internal object ids.')
518
_global_option('timezone',
540
_global_option('timezone',
520
help='display timezone as local, original, or utc')
542
help='Display timezone as local, original, or utc.')
521
543
_global_option('unbound')
522
544
_global_option('version')
523
545
_global_option('email')
524
546
_global_option('update')
525
547
_global_registry_option('log-format', "Use specified log format.",
526
log.log_formatter_registry, value_switches=True,
548
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
549
value_switches=True, title='Log format')
528
550
_global_option('long', help='Use detailed log format. Same as --log-format long',
530
552
_global_option('short', help='Use moderately short log format. Same as --log-format short')