~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Aaron Bentley
  • Date: 2006-08-16 04:57:05 UTC
  • mto: This revision was merged to the branch mainline in revision 1934.
  • Revision ID: aaron.bentley@utoronto.ca-20060816045705-b4e53acd83d8acb7
Strip out all the EnumOption stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
            (typestring, type_list)
114
114
        raise BzrCommandError(msg)
115
115
 
116
 
class EnumOption(object):
117
 
 
118
 
    def __init__(self, name, factory, choices):
119
 
        self.name = name
120
 
        self.factory = factory
121
 
        self.choices = choices 
122
 
        self.default = None
123
 
 
124
 
    def python_name(self):
125
 
        """Conver a name with spaces and caps to a python variable name"""
126
 
        return self.name.lower().replace(' ', '_')
127
 
 
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,),
136
 
                              metavar=self.name,
137
 
                              help=help,
138
 
                              default=OptionParser.DEFAULT_VALUE,
139
 
                              dest=self.python_name(),
140
 
                              *option_strings)
141
 
        parser.add_option_group(group)
142
 
 
143
 
    def _optparse_callback(self, option, opt, value, parser, evalue):
144
 
        setattr(parser.values, option.dest, self.factory(evalue))
145
 
 
146
 
    def iter_switches(self):
147
 
        """Iterate through the list of switches provided by the option
148
 
        
149
 
        :return: an iterator of (name, short_name, argname, help)
150
 
        """
151
 
        return ((n, None, None, h) for n, h in self.choices)
152
 
 
153
 
 
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)
263
225
 
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')])
268
 
 
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')])
273
 
 
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']