110
110
raise errors.BzrCommandError(msg)
112
112
class Option(object):
113
"""Description of a command line option"""
113
"""Description of a command line option
115
:ivar short_name: If this option has a single-letter name, this is it.
114
119
# TODO: Some way to show in help a description of the option argument
119
def __init__(self, name, help='', type=None, argname=None):
123
def __init__(self, name, help='', type=None, argname=None,
120
125
"""Make a new command option.
122
127
name -- regular name of the command, used in the double-dash
131
136
argname -- name of option argument, if any
133
# TODO: perhaps a subclass that automatically does
134
# --option, --no-option for reversible booleans
141
self.short_name = short_name
139
143
assert argname is None
140
144
elif argname is None:
142
146
self.argname = argname
144
def short_name(self):
145
"""Return the single character option for this command, if any.
147
Short options are globally registered.
149
for short, option in Option.SHORT_OPTIONS.iteritems():
153
148
def get_negation_name(self):
154
149
if self.name.startswith('no-'):
155
150
return self.name[3:]
189
184
argname = self.argname
190
185
if argname is not None:
191
186
argname = argname.upper()
192
yield self.name, self.short_name(), argname, self.help
187
yield self.name, self.short_name, argname, self.help
195
190
class OptionParser(optparse.OptionParser):
207
202
parser = OptionParser()
208
203
parser.remove_option('--help')
209
short_options = dict((k.name, v) for v, k in
210
Option.SHORT_OPTIONS.iteritems())
211
204
for option in options.itervalues():
212
option.add_option(parser, short_options.get(option.name))
205
option.add_option(parser, option.short_name)
224
217
_global_option('bound')
225
218
_global_option('diff-options', type=str)
226
219
_global_option('help',
227
help='show help message')
228
_global_option('file', type=unicode)
220
help='show help message',
222
_global_option('file', type=unicode, short_name='F')
229
223
_global_option('force')
230
224
_global_option('format', type=unicode)
231
225
_global_option('forward')
232
_global_option('message', type=unicode)
226
_global_option('message', type=unicode,
233
228
_global_option('no-recurse')
234
_global_option('prefix', type=str,
235
help='Set prefixes to added to old and new filenames, as '
236
'two values separated by a colon.')
237
229
_global_option('profile',
238
230
help='show performance profiling information')
239
_global_option('revision', type=_parse_revision_str)
231
_global_option('revision',
232
type=_parse_revision_str,
240
234
_global_option('show-ids',
241
235
help='show internal object ids')
242
236
_global_option('timezone',
244
238
help='display timezone as local, original, or utc')
245
239
_global_option('unbound')
246
240
_global_option('verbose',
247
help='display more information')
241
help='display more information',
248
243
_global_option('version')
249
244
_global_option('email')
250
245
_global_option('update')
251
246
_global_option('log-format', type=str, help="Use this log format")
252
_global_option('long', help='Use detailed log format. Same as --log-format long')
247
_global_option('long', help='Use detailed log format. Same as --log-format long',
253
249
_global_option('short', help='Use moderately short log format. Same as --log-format short')
254
250
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
255
251
_global_option('root', type=str)
257
253
_global_option('merge-type', type=_parse_merge_type,
258
254
help='Select a particular merge algorithm')
259
255
_global_option('pattern', type=str)
260
_global_option('quiet')
256
_global_option('quiet', short_name='q')
261
257
_global_option('remember', help='Remember the specified location as a'
263
259
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
265
261
_global_option('dry-run',
266
262
help="show what would be done, but don't actually do anything")
267
263
_global_option('name-from-revision', help='The path name in the old tree.')
270
def _global_short(short_name, long_name):
271
assert short_name not in Option.SHORT_OPTIONS
272
Option.SHORT_OPTIONS[short_name] = Option.OPTIONS[long_name]
275
Option.SHORT_OPTIONS['F'] = Option.OPTIONS['file']
276
Option.SHORT_OPTIONS['h'] = Option.OPTIONS['help']
277
Option.SHORT_OPTIONS['m'] = Option.OPTIONS['message']
278
Option.SHORT_OPTIONS['r'] = Option.OPTIONS['revision']
279
Option.SHORT_OPTIONS['v'] = Option.OPTIONS['verbose']
280
Option.SHORT_OPTIONS['l'] = Option.OPTIONS['long']
281
Option.SHORT_OPTIONS['q'] = Option.OPTIONS['quiet']
282
Option.SHORT_OPTIONS['p'] = Option.OPTIONS['prefix']