~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-13 20:33:57 UTC
  • mfrom: (2283 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070213203357-b7yg41mi9sk6cqd0
[merge] bzr.dev 2283
resolve conflicts in moved repository formats
small issue with osutils.contains_whitespace()

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from bzrlib import (
27
27
    errors,
 
28
    log,
 
29
    registry,
28
30
    revisionspec,
29
31
    symbol_versioning,
30
32
    )
225
227
            return self.converter(value)
226
228
 
227
229
    def __init__(self, name, help, registry, converter=None,
228
 
        value_switches=False):
 
230
        value_switches=False, title=None):
229
231
        """
230
232
        Constructor.
231
233
 
235
237
        :param converter: Callable to invoke with the value name to produce
236
238
            the value.  If not supplied, self.registry.get is used.
237
239
        :param value_switches: If true, each possible value is assigned its
238
 
            own switch.  For example, instead of '--format metaweave',
239
 
            '--metaweave' can be used interchangeably.
 
240
            own switch.  For example, instead of '--format knit',
 
241
            '--knit' can be used interchangeably.
240
242
        """
241
243
        Option.__init__(self, name, help, type=self.convert)
242
244
        self.registry = registry
243
245
        self.name = name
244
246
        self.converter = converter
245
247
        self.value_switches = value_switches
 
248
        self.title = title
 
249
        if self.title is None:
 
250
            self.title = name
246
251
 
247
252
    def add_option(self, parser, short_name):
248
253
        """Add this option to an Optparse parser"""
 
254
        if self.value_switches:
 
255
            parser = parser.add_option_group(self.title)
249
256
        Option.add_option(self, parser, short_name)
250
257
        if self.value_switches:
251
258
            for key in self.registry.keys():
295
302
    """Register o as a global option."""
296
303
    Option.OPTIONS[name] = Option(name, **kwargs)
297
304
 
 
305
 
 
306
def _global_registry_option(name, help, registry, **kwargs):
 
307
    Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
 
308
 
 
309
 
 
310
class MergeTypeRegistry(registry.Registry):
 
311
 
 
312
    pass
 
313
 
 
314
 
 
315
_merge_type_registry = MergeTypeRegistry()
 
316
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
 
317
                                   "Native diff3-style merge")
 
318
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
 
319
                                   "Merge using external diff3")
 
320
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
 
321
                                   "Weave-based merge")
 
322
 
298
323
_global_option('all')
299
324
_global_option('overwrite', help='Ignore differences between branches and '
300
325
               'overwrite unconditionally')
329
354
_global_option('version')
330
355
_global_option('email')
331
356
_global_option('update')
332
 
_global_option('log-format', type=str, help="Use this log format")
 
357
_global_registry_option('log-format', "Use this log format",
 
358
                        log.log_formatter_registry, value_switches=True,
 
359
                        title='Log format')
333
360
_global_option('long', help='Use detailed log format. Same as --log-format long',
334
361
               short_name='l')
335
362
_global_option('short', help='Use moderately short log format. Same as --log-format short')
336
363
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
337
364
_global_option('root', type=str)
338
365
_global_option('no-backup')
339
 
_global_option('merge-type', type=_parse_merge_type, 
340
 
               help='Select a particular merge algorithm')
 
366
_global_registry_option('merge-type', 'Select a particular merge algorithm',
 
367
                        _merge_type_registry, value_switches=True,
 
368
                        title='Merge algorithm')
341
369
_global_option('pattern', type=str)
342
370
_global_option('quiet', short_name='q')
343
371
_global_option('remember', help='Remember the specified location as a'