108
108
class Option(object):
109
"""Description of a command line option"""
110
# TODO: Some way to show in help a description of the option argument
110
113
SHORT_OPTIONS = {}
112
def __init__(self, name, help='help string', type=None):
113
# need to add some description of the parameters here
115
def __init__(self, name, help='', type=None):
116
"""Make a new command option.
118
name -- regular name of the command, used in the double-dash
119
form and also as the parameter to the command's run()
122
help -- help message displayed in command help
124
type -- function called to parse the option argument, or
125
None (default) if this option doesn't take an argument.
127
# TODO: perhaps a subclass that automatically does
128
# --option, --no-option for reversable booleans
133
def short_name(self):
134
"""Return the single character option for this command, if any.
136
Short options are globally registered.
138
return Option.SHORT_OPTIONS.get(self.name)
118
141
def _global_option(name, **kwargs):
119
142
"""Register o as a global option."""
120
143
Option.OPTIONS[name] = Option(name, **kwargs)
122
_global_option('all', type=None)
145
_global_option('all')
123
146
_global_option('basis', type=str)
124
147
_global_option('diff-options', type=str)
125
_global_option('help', type=None)
148
_global_option('help')
126
149
_global_option('file', type=unicode)
127
_global_option('force', type=None)
150
_global_option('force')
128
151
_global_option('format', type=unicode)
129
_global_option('forward', type=None)
152
_global_option('forward')
130
153
_global_option('message', type=unicode)
131
_global_option('no-recurse', type=None)
132
_global_option('profile', type=None)
154
_global_option('no-recurse')
155
_global_option('profile')
133
156
_global_option('revision', type=_parse_revision_str)
134
_global_option('short', type=None)
135
_global_option('show-ids', type=None)
157
_global_option('short')
158
_global_option('show-ids')
136
159
_global_option('timezone', type=str)
137
_global_option('verbose', type=None)
138
_global_option('version', type=None)
139
_global_option('email', type=None)
140
_global_option('unchanged', type=None)
141
_global_option('update', type=None)
142
_global_option('long', type=None)
160
_global_option('verbose')
161
_global_option('version')
162
_global_option('email')
163
_global_option('unchanged')
164
_global_option('update')
165
_global_option('long')
143
166
_global_option('root', type=str)
144
_global_option('no-backup', type=None)
167
_global_option('no-backup')
145
168
_global_option('merge-type', type=_parse_merge_type)
146
169
_global_option('pattern', type=str)
147
_global_option('quiet', type=None)
148
_global_option('remember', type=None)
170
_global_option('quiet')
171
_global_option('remember')
174
def _global_short(short_name, long_name):
175
assert short_name not in Option.SHORT_OPTIONS
176
Option.SHORT_OPTIONS[short_name] = Option.OPTIONS[long_name]
150
179
Option.SHORT_OPTIONS['F'] = Option.OPTIONS['file']
151
180
Option.SHORT_OPTIONS['h'] = Option.OPTIONS['help']