17
17
# TODO: For things like --diff-prefix, we want a way to customize the display
18
18
# of the option argument.
23
22
from bzrlib.lazy_import import lazy_import
24
23
lazy_import(globals(), """
25
26
from bzrlib import (
32
registry as _mod_registry,
34
from bzrlib.trace import warning
36
37
def _parse_revision_str(revstr):
180
181
self._short_name = short_name
183
raise ValueError('argname not valid for booleans')
183
assert argname is None
184
184
elif argname is None:
186
186
self.argname = argname
187
187
if param_name is None:
188
self._param_name = self.name.replace('-', '_')
188
self._param_name = self.name
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=None, converter=None,
310
value_switches=False, title=None, enum_switch=True,
309
def __init__(self, name, help, registry, converter=None,
310
value_switches=False, title=None, enum_switch=True):
322
321
'--knit' can be used interchangeably.
323
322
:param enum_switch: If true, a switch is provided with the option name,
324
323
which takes a value.
325
:param lazy_registry: A tuple of (module name, attribute name) for a
326
registry to be lazily loaded.
328
325
Option.__init__(self, name, help, type=self.convert)
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')
326
self.registry = registry
340
328
self.converter = converter
341
329
self.value_switches = value_switches
344
332
if self.title is None:
345
333
self.title = name
349
if self._registry is None:
350
self._registry = self._lazy_registry.get_obj()
351
return self._registry
354
336
def from_kwargs(name_, help=None, title=None, value_switches=False,
355
337
enum_switch=True, **kwargs):
359
341
RegistryOption constructor. Any other keyword arguments are treated
360
342
as values for the option, and they value is treated as the help.
362
reg = _mod_registry.Registry()
344
reg = registry.Registry()
363
345
for name, switch_help in kwargs.iteritems():
364
346
name = name.replace('_', '-')
365
347
reg.register(name, name, help=switch_help)
366
if not value_switches:
367
help = help + ' "' + name + '": ' + switch_help
368
if not help.endswith("."):
370
348
return RegistryOption(name_, help, reg, title=title,
371
349
value_switches=value_switches, enum_switch=enum_switch)
452
430
Option.OPTIONS[name] = Option(name, **kwargs)
455
def _global_registry_option(name, help, registry=None, **kwargs):
433
def _global_registry_option(name, help, registry, **kwargs):
456
434
Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
437
class MergeTypeRegistry(registry.Registry):
459
442
# This is the verbosity level detected during command line parsing.
460
443
# Note that the final value is dependent on the order in which the
461
444
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
484
467
_verbosity_level = -1
487
class MergeTypeRegistry(_mod_registry.Registry):
492
470
_merge_type_registry = MergeTypeRegistry()
493
471
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
494
472
"Native diff3-style merge")
496
474
"Merge using external diff3")
497
475
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
498
476
"Weave-based merge")
499
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
502
478
# Declare the standard options
503
479
_standard_option('help', short_name='h',
537
513
help='Select changes introduced by the specified revision. See also "help revisionspec".')
538
514
_global_option('show-ids',
539
515
help='Show internal object ids.')
540
_global_option('timezone',
516
_global_option('timezone',
542
help='Display timezone as local, original, or utc.')
518
help='display timezone as local, original, or utc')
543
519
_global_option('unbound')
544
520
_global_option('version')
545
521
_global_option('email')
546
522
_global_option('update')
547
523
_global_registry_option('log-format', "Use specified log format.",
548
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
549
value_switches=True, title='Log format')
524
log.log_formatter_registry, value_switches=True,
550
526
_global_option('long', help='Use detailed log format. Same as --log-format long',
552
528
_global_option('short', help='Use moderately short log format. Same as --log-format short')
564
540
_global_option('dry-run',
565
541
help="Show what would be done, but don't actually do anything.")
566
542
_global_option('name-from-revision', help='The path name in the old tree.')
568
diff_writer_registry = _mod_registry.Registry()
569
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')
570
diff_writer_registry.default_key = 'plain'