152
152
def short_name(self):
153
153
if self._short_name:
154
154
return self._short_name
156
# remove this when SHORT_OPTIONS is removed
157
# XXX: This is accessing a DeprecatedDict, so we call the super
158
# method to avoid warnings
159
for (k, v) in dict.iteritems(Option.SHORT_OPTIONS):
163
156
def set_short_name(self, short_name):
164
157
self._short_name = short_name
205
198
yield self.name, self.short_name(), argname, self.help
201
class ListOption(Option):
202
"""Option used to provide a list of values.
204
On the command line, arguments are specified by a repeated use of the
205
option. '-' is a special argument that resets the list. For example,
207
sets the value of the 'foo' option to ['a', 'b'], and
208
--foo=a --foo=b --foo=- --foo=c
209
sets the value of the 'foo' option to ['c'].
212
def add_option(self, parser, short_name):
213
"""Add this option to an Optparse parser."""
214
option_strings = ['--%s' % self.name]
215
if short_name is not None:
216
option_strings.append('-%s' % short_name)
217
parser.add_option(action='callback',
218
callback=self._optparse_callback,
219
type='string', metavar=self.argname.upper(),
220
help=self.help, default=[],
223
def _optparse_callback(self, option, opt, value, parser):
224
values = getattr(parser.values, self.name)
228
values.append(self.type(value))
208
231
class RegistryOption(Option):
209
232
"""Option based on a registry
227
250
return self.converter(value)
229
252
def __init__(self, name, help, registry, converter=None,
230
value_switches=False, title=None):
253
value_switches=False, title=None, enum_switch=True):
239
262
:param value_switches: If true, each possible value is assigned its
240
263
own switch. For example, instead of '--format knit',
241
264
'--knit' can be used interchangeably.
265
:param enum_switch: If true, a switch is provided with the option name,
243
268
Option.__init__(self, name, help, type=self.convert)
244
269
self.registry = registry
246
271
self.converter = converter
247
272
self.value_switches = value_switches
273
self.enum_switch = enum_switch
248
274
self.title = title
249
275
if self.title is None:
250
276
self.title = name
279
def from_kwargs(name_, help=None, title=None, value_switches=False,
280
enum_switch=True, **kwargs):
281
"""Convenience method to generate string-map registry options
283
name, help, value_switches and enum_switch are passed to the
284
RegistryOption constructor. Any other keyword arguments are treated
285
as values for the option, and they value is treated as the help.
287
reg = registry.Registry()
288
for name, help in kwargs.iteritems():
289
name = name.replace('_', '-')
290
reg.register(name, name, help=help)
291
return RegistryOption(name_, help, reg, title=title,
292
value_switches=value_switches, enum_switch=enum_switch)
252
294
def add_option(self, parser, short_name):
253
295
"""Add this option to an Optparse parser"""
254
296
if self.value_switches:
255
297
parser = parser.add_option_group(self.title)
256
Option.add_option(self, parser, short_name)
299
Option.add_option(self, parser, short_name)
257
300
if self.value_switches:
258
301
for key in self.registry.keys():
259
302
option_strings = ['--%s' % key]
303
if getattr(self.registry.get_info(key), 'hidden', False):
304
help = optparse.SUPPRESS_HELP
306
help = self.registry.get_help(key)
260
307
parser.add_option(action='callback',
261
308
callback=self._optparse_value_callback(key),
262
help=self.registry.get_help(key),
265
312
def _optparse_value_callback(self, cb_value):
323
370
_global_option('all')
324
371
_global_option('overwrite', help='Ignore differences between branches and '
325
'overwrite unconditionally')
372
'overwrite unconditionally.')
326
373
_global_option('basis', type=str)
327
374
_global_option('bound')
328
375
_global_option('diff-options', type=str)
329
_global_option('help',
330
help='show help message',
332
376
_global_option('file', type=unicode, short_name='F')
333
377
_global_option('force')
334
378
_global_option('format', type=unicode)
335
379
_global_option('forward')
336
380
_global_option('message', type=unicode,
382
help='Message string.')
338
383
_global_option('no-recurse')
339
384
_global_option('profile',
340
help='show performance profiling information')
385
help='Show performance profiling information.')
341
386
_global_option('revision',
342
387
type=_parse_revision_str,
344
help='See \'help revisionspec\' for details')
345
_global_option('show-ids',
346
help='show internal object ids')
389
help='See \'help revisionspec\' for details.')
390
_global_option('show-ids',
391
help='Show internal object ids.')
347
392
_global_option('timezone',
349
394
help='display timezone as local, original, or utc')
350
395
_global_option('unbound')
351
396
_global_option('verbose',
352
help='display more information',
397
help='Display more information.',
354
399
_global_option('version')
355
400
_global_option('email')
356
401
_global_option('update')
357
_global_registry_option('log-format', "Use this log format",
402
_global_registry_option('log-format', "Use specified log format.",
358
403
log.log_formatter_registry, value_switches=True,
359
404
title='Log format')
360
405
_global_option('long', help='Use detailed log format. Same as --log-format long',
363
408
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
364
409
_global_option('root', type=str)
365
410
_global_option('no-backup')
366
_global_registry_option('merge-type', 'Select a particular merge algorithm',
411
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
367
412
_merge_type_registry, value_switches=True,
368
413
title='Merge algorithm')
369
414
_global_option('pattern', type=str)
370
415
_global_option('quiet', short_name='q')
371
416
_global_option('remember', help='Remember the specified location as a'
373
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
418
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
374
419
_global_option('kind', type=str)
375
420
_global_option('dry-run',
376
help="show what would be done, but don't actually do anything")
421
help="Show what would be done, but don't actually do anything.")
377
422
_global_option('name-from-revision', help='The path name in the old tree.')
380
# prior to 0.14 these were always globally registered; the old dict is
381
# available for plugins that use it but it should not be used.
382
Option.SHORT_OPTIONS = symbol_versioning.DeprecatedDict(
383
symbol_versioning.zero_fourteen,
386
'F': Option.OPTIONS['file'],
387
'h': Option.OPTIONS['help'],
388
'm': Option.OPTIONS['message'],
389
'r': Option.OPTIONS['revision'],
390
'v': Option.OPTIONS['verbose'],
391
'l': Option.OPTIONS['long'],
392
'q': Option.OPTIONS['quiet'],
394
'Set the short option name when constructing the Option.',
424
_help_option = Option('help',
425
help='Show help message.',