/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/option.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    )
30
30
from .sixish import (
31
31
    text_type,
 
32
    viewitems,
32
33
    )
33
34
 
34
35
 
123
124
def _parse_merge_type(typestring):
124
125
    return get_merge_type(typestring)
125
126
 
126
 
 
127
127
def get_merge_type(typestring):
128
128
    """Attempt to find the merge class/factory associated with a string."""
129
129
    from merge import merge_types
130
130
    try:
131
131
        return merge_types[typestring][0]
132
132
    except KeyError:
133
 
        templ = '%s%%7s: %%s' % (' ' * 12)
 
133
        templ = '%s%%7s: %%s' % (' '*12)
134
134
        lines = [templ % (f[0], f[1][1]) for f in merge_types.items()]
135
135
        type_list = '\n'.join(lines)
136
136
        msg = "No known merge type %s. Supported types are:\n%s" %\
246
246
            self.custom_callback(option, self._param_name, bool_v, parser)
247
247
 
248
248
    def _optparse_callback(self, option, opt, value, parser):
249
 
        try:
250
 
            v = self.type(value)
251
 
        except ValueError as e:
252
 
            raise optparse.OptionValueError(
253
 
                'invalid value for option %s: %s' % (option, value))
 
249
        v = self.type(value)
254
250
        setattr(parser.values, self._param_name, v)
255
251
        if self.custom_callback is not None:
256
252
            self.custom_callback(option, self.name, v, parser)
260
256
 
261
257
        :return: an iterator of (name, short_name, argname, help)
262
258
        """
263
 
        argname = self.argname
 
259
        argname =  self.argname
264
260
        if argname is not None:
265
261
            argname = argname.upper()
266
262
        yield self.name, self.short_name(), argname, self.help
323
319
            return self.converter(value)
324
320
 
325
321
    def __init__(self, name, help, registry=None, converter=None,
326
 
                 value_switches=False, title=None, enum_switch=True,
327
 
                 lazy_registry=None, short_name=None, short_value_switches=None):
 
322
        value_switches=False, title=None, enum_switch=True,
 
323
        lazy_registry=None, short_name=None, short_value_switches=None):
328
324
        """
329
325
        Constructor.
330
326
 
388
384
                if not help.endswith("."):
389
385
                    help = help + "."
390
386
        return RegistryOption(name_, help, reg, title=title,
391
 
                              value_switches=value_switches, enum_switch=enum_switch)
 
387
            value_switches=value_switches, enum_switch=enum_switch)
392
388
 
393
389
    def add_option(self, parser, short_name):
394
390
        """Add this option to an Optparse parser"""
411
407
                else:
412
408
                    help = self.registry.get_help(key)
413
409
                if (self.short_value_switches and
414
 
                        key in self.short_value_switches):
 
410
                    key in self.short_value_switches):
415
411
                    option_strings.append('-%s' %
416
412
                                          self.short_value_switches[key])
417
413
                parser.add_option(action='callback',
418
 
                                  callback=self._optparse_value_callback(key),
 
414
                              callback=self._optparse_value_callback(key),
419
415
                                  help=help,
420
416
                                  *option_strings)
421
417
 
465
461
 
466
462
class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
467
463
    """Adds gettext() call to format_option()"""
468
 
 
469
464
    def __init__(self):
470
465
        optparse.IndentedHelpFormatter.__init__(self)
471
466
 
482
477
 
483
478
    parser = OptionParser()
484
479
    parser.remove_option('--help')
485
 
    for option in options:
 
480
    for option in options.values():
486
481
        option.add_option(parser, option.short_name())
487
482
    return parser
488
483
 
501
496
    Option.STD_OPTIONS[name] = Option(name, **kwargs)
502
497
    Option.OPTIONS[name] = Option.STD_OPTIONS[name]
503
498
 
504
 
 
505
499
def _standard_list_option(name, **kwargs):
506
500
    """Register a standard option."""
507
501
    # All standard options are implicitly 'global' ones
578
572
               short_name='m',
579
573
               help='Message string.')
580
574
_global_option('null', short_name='0',
581
 
               help='Use an ASCII NUL (\\0) separator rather than '
582
 
               'a newline.')
 
575
                 help='Use an ASCII NUL (\\0) separator rather than '
 
576
                      'a newline.')
583
577
_global_option('overwrite', help='Ignore differences between branches and '
584
578
               'overwrite unconditionally.')
585
579
_global_option('remember', help='Remember the specified location as a'