113
113
(typestring, type_list)
114
114
raise BzrCommandError(msg)
116
class EnumOption(object):
118
def __init__(self, name, factory, choices):
120
self.factory = factory
121
self.choices = choices
124
def python_name(self):
125
"""Conver a name with spaces and caps to a python variable name"""
126
return self.name.lower().replace(' ', '_')
128
def add_option(self, parser, short_name):
129
"""Add this option to an Optparse parser"""
130
group = optparse.OptionGroup(parser, self.name)
131
for name, help in self.choices:
132
option_strings = ['--%s' % name]
133
group.add_option(action='callback',
134
callback=self._optparse_callback,
135
callback_args=(name,),
138
default=OptionParser.DEFAULT_VALUE,
139
dest=self.python_name(),
141
parser.add_option_group(group)
143
def _optparse_callback(self, option, opt, value, parser, evalue):
144
setattr(parser.values, option.dest, self.factory(evalue))
146
def iter_switches(self):
147
"""Iterate through the list of switches provided by the option
149
:return: an iterator of (name, short_name, argname, help)
151
return ((n, None, None, h) for n, h in self.choices)
154
116
class Option(object):
155
117
"""Description of a command line option"""
156
118
# TODO: Some way to show in help a description of the option argument
261
223
"""Register o as a global option."""
262
224
Option.OPTIONS[name] = Option(name, **kwargs)
264
Option.OPTIONS['merge-type']=EnumOption('Merge type', get_merge_type, [
265
('merge3', 'Use built-in diff3-style merge'),
266
('diff3', 'Use external diff3 merge'),
267
('weave', 'Use knit merge')])
269
Option.OPTIONS['log-format']=EnumOption('Log format', str, [
270
('long', 'Multi-line logs with merges shown'),
271
('short', 'Two-line logs'),
272
('line', 'One-line logs')])
274
226
_global_option('all')
275
227
_global_option('overwrite', help='Ignore differences between branches and '
276
228
'overwrite unconditionally')
302
254
_global_option('version')
303
255
_global_option('email')
304
256
_global_option('update')
257
_global_option('log-format', type=str, help="Use this log format")
258
_global_option('long', help='Use detailed log format. Same as --log-format long')
259
_global_option('short', help='Use moderately short log format. Same as --log-format short')
260
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
305
261
_global_option('root', type=str)
306
262
_global_option('no-backup')
263
_global_option('merge-type', type=_parse_merge_type,
264
help='Select a particular merge algorithm')
307
265
_global_option('pattern', type=str)
308
266
_global_option('quiet')
309
267
_global_option('remember', help='Remember the specified location as a'
324
282
Option.SHORT_OPTIONS['m'] = Option.OPTIONS['message']
325
283
Option.SHORT_OPTIONS['r'] = Option.OPTIONS['revision']
326
284
Option.SHORT_OPTIONS['v'] = Option.OPTIONS['verbose']
285
Option.SHORT_OPTIONS['l'] = Option.OPTIONS['long']
327
286
Option.SHORT_OPTIONS['q'] = Option.OPTIONS['quiet']
328
287
Option.SHORT_OPTIONS['p'] = Option.OPTIONS['prefix']