13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
# TODO: For things like --diff-prefix, we want a way to customize the display
18
18
# of the option argument.
152
152
def __init__(self, name, help='', type=None, argname=None,
153
short_name=None, param_name=None, custom_callback=None,
153
short_name=None, param_name=None, custom_callback=None):
155
154
"""Make a new command option.
157
156
:param name: regular name of the command, used in the double-dash
158
form and also as the parameter to the command's run()
157
form and also as the parameter to the command's run()
159
158
method (unless param_name is specified).
161
160
:param help: help message displayed in command help
163
:param type: function called to parse the option argument, or
162
:param type: function called to parse the option argument, or
164
163
None (default) if this option doesn't take an argument.
166
165
:param argname: name of option argument, if any
174
173
:param custom_callback: a callback routine to be called after normal
175
174
processing. The signature of the callback routine is
176
175
(option, name, new_value, parser).
177
:param hidden: If True, the option should be hidden in help and
189
186
self.argname = argname
190
187
if param_name is None:
191
self._param_name = self.name.replace('-', '_')
188
self._param_name = self.name
193
190
self._param_name = param_name
194
191
self.custom_callback = custom_callback
197
193
def short_name(self):
198
194
if self._short_name:
212
208
option_strings = ['--%s' % self.name]
213
209
if short_name is not None:
214
210
option_strings.append('-%s' % short_name)
216
help = optparse.SUPPRESS_HELP
219
211
optargfn = self.type
220
212
if optargfn is None:
221
parser.add_option(action='callback',
222
callback=self._optparse_bool_callback,
213
parser.add_option(action='callback',
214
callback=self._optparse_bool_callback,
223
215
callback_args=(True,),
226
218
negation_strings = ['--%s' % self.get_negation_name()]
227
parser.add_option(action='callback',
228
callback=self._optparse_bool_callback,
219
parser.add_option(action='callback',
220
callback=self._optparse_bool_callback,
229
221
callback_args=(False,),
230
222
help=optparse.SUPPRESS_HELP, *negation_strings)
232
parser.add_option(action='callback',
233
callback=self._optparse_callback,
224
parser.add_option(action='callback',
225
callback=self._optparse_callback,
234
226
type='string', metavar=self.argname.upper(),
236
default=OptionParser.DEFAULT_VALUE,
228
default=OptionParser.DEFAULT_VALUE,
239
231
def _optparse_bool_callback(self, option, opt_str, value, parser, bool_v):
258
250
yield self.name, self.short_name(), argname, self.help
260
252
def is_hidden(self, name):
264
256
class ListOption(Option):
315
307
return self.converter(value)
317
def __init__(self, name, help, registry=None, converter=None,
318
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):
330
321
'--knit' can be used interchangeably.
331
322
:param enum_switch: If true, a switch is provided with the option name,
332
323
which takes a value.
333
:param lazy_registry: A tuple of (module name, attribute name) for a
334
registry to be lazily loaded.
336
325
Option.__init__(self, name, help, type=self.convert)
337
self._registry = registry
339
if lazy_registry is None:
340
raise AssertionError(
341
'One of registry or lazy_registry must be given.')
342
self._lazy_registry = _mod_registry._LazyObjectGetter(
344
if registry is not None and lazy_registry is not None:
345
raise AssertionError(
346
'registry and lazy_registry are mutually exclusive')
326
self.registry = registry
348
328
self.converter = converter
349
329
self.value_switches = value_switches
352
332
if self.title is None:
353
333
self.title = name
357
if self._registry is None:
358
self._registry = self._lazy_registry.get_obj()
359
return self._registry
362
336
def from_kwargs(name_, help=None, title=None, value_switches=False,
363
337
enum_switch=True, **kwargs):
367
341
RegistryOption constructor. Any other keyword arguments are treated
368
342
as values for the option, and they value is treated as the help.
370
reg = _mod_registry.Registry()
344
reg = registry.Registry()
371
345
for name, switch_help in kwargs.iteritems():
372
346
name = name.replace('_', '-')
373
347
reg.register(name, name, help=switch_help)
460
434
Option.OPTIONS[name] = Option(name, **kwargs)
463
def _global_registry_option(name, help, registry=None, **kwargs):
437
def _global_registry_option(name, help, registry, **kwargs):
464
438
Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
441
class MergeTypeRegistry(registry.Registry):
467
446
# This is the verbosity level detected during command line parsing.
468
447
# Note that the final value is dependent on the order in which the
469
448
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
492
471
_verbosity_level = -1
495
class MergeTypeRegistry(_mod_registry.Registry):
500
474
_merge_type_registry = MergeTypeRegistry()
501
475
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
502
476
"Native diff3-style merge")
510
484
# Declare the standard options
511
485
_standard_option('help', short_name='h',
512
486
help='Show help message.')
513
_standard_option('usage',
514
help='Show usage message and options.')
515
487
_standard_option('verbose', short_name='v',
516
488
help='Display more information.',
517
489
custom_callback=_verbosity_level_callback)
547
519
help='Select changes introduced by the specified revision. See also "help revisionspec".')
548
520
_global_option('show-ids',
549
521
help='Show internal object ids.')
550
_global_option('timezone',
522
_global_option('timezone',
552
help='Display timezone as local, original, or utc.')
524
help='display timezone as local, original, or utc')
553
525
_global_option('unbound')
554
526
_global_option('version')
555
527
_global_option('email')
556
528
_global_option('update')
557
529
_global_registry_option('log-format', "Use specified log format.",
558
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
559
value_switches=True, title='Log format')
530
log.log_formatter_registry, value_switches=True,
560
532
_global_option('long', help='Use detailed log format. Same as --log-format long',
562
534
_global_option('short', help='Use moderately short log format. Same as --log-format short')
574
546
_global_option('dry-run',
575
547
help="Show what would be done, but don't actually do anything.")
576
548
_global_option('name-from-revision', help='The path name in the old tree.')
578
diff_writer_registry = _mod_registry.Registry()
579
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')
580
diff_writer_registry.default_key = 'plain'