1
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
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
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):
156
163
def set_short_name(self, short_name):
157
164
self._short_name = short_name
198
205
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))
231
208
class RegistryOption(Option):
232
209
"""Option based on a registry
300
277
if self.value_switches:
301
278
for key in self.registry.keys():
302
279
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)
307
280
parser.add_option(action='callback',
308
281
callback=self._optparse_value_callback(key),
282
help=self.registry.get_help(key),
312
285
def _optparse_value_callback(self, cb_value):
370
343
_global_option('all')
371
344
_global_option('overwrite', help='Ignore differences between branches and '
372
'overwrite unconditionally.')
345
'overwrite unconditionally')
373
346
_global_option('basis', type=str)
374
347
_global_option('bound')
375
348
_global_option('diff-options', type=str)
349
_global_option('help',
350
help='show help message',
376
352
_global_option('file', type=unicode, short_name='F')
377
353
_global_option('force')
378
354
_global_option('format', type=unicode)
379
355
_global_option('forward')
380
356
_global_option('message', type=unicode,
382
help='Message string.')
383
358
_global_option('no-recurse')
384
359
_global_option('profile',
385
help='Show performance profiling information.')
360
help='show performance profiling information')
386
361
_global_option('revision',
387
362
type=_parse_revision_str,
389
help='See \'help revisionspec\' for details.')
390
_global_option('show-ids',
391
help='Show internal object ids.')
364
help='See \'help revisionspec\' for details')
365
_global_option('show-ids',
366
help='show internal object ids')
392
367
_global_option('timezone',
394
369
help='display timezone as local, original, or utc')
395
370
_global_option('unbound')
396
371
_global_option('verbose',
397
help='Display more information.',
372
help='display more information',
399
374
_global_option('version')
400
375
_global_option('email')
401
376
_global_option('update')
402
_global_registry_option('log-format', "Use specified log format.",
377
_global_registry_option('log-format', "Use this log format",
403
378
log.log_formatter_registry, value_switches=True,
404
379
title='Log format')
405
380
_global_option('long', help='Use detailed log format. Same as --log-format long',
408
383
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
409
384
_global_option('root', type=str)
410
385
_global_option('no-backup')
411
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
386
_global_registry_option('merge-type', 'Select a particular merge algorithm',
412
387
_merge_type_registry, value_switches=True,
413
388
title='Merge algorithm')
414
389
_global_option('pattern', type=str)
415
390
_global_option('quiet', short_name='q')
416
391
_global_option('remember', help='Remember the specified location as a'
418
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
393
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
419
394
_global_option('kind', type=str)
420
395
_global_option('dry-run',
421
help="Show what would be done, but don't actually do anything.")
396
help="show what would be done, but don't actually do anything")
422
397
_global_option('name-from-revision', help='The path name in the old tree.')
424
_help_option = Option('help',
425
help='Show help message.',
400
# prior to 0.14 these were always globally registered; the old dict is
401
# available for plugins that use it but it should not be used.
402
Option.SHORT_OPTIONS = symbol_versioning.DeprecatedDict(
403
symbol_versioning.zero_fourteen,
406
'F': Option.OPTIONS['file'],
407
'h': Option.OPTIONS['help'],
408
'm': Option.OPTIONS['message'],
409
'r': Option.OPTIONS['revision'],
410
'v': Option.OPTIONS['verbose'],
411
'l': Option.OPTIONS['long'],
412
'q': Option.OPTIONS['quiet'],
414
'Set the short option name when constructing the Option.',