~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Aaron Bentley
  • Date: 2009-04-03 20:05:25 UTC
  • mto: This revision was merged to the branch mainline in revision 4266.
  • Revision ID: aaron@aaronbentley.com-20090403200525-5vcdyhnjrlsqd6dr
Support hidden options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
    OPTIONS = {}
151
151
 
152
152
    def __init__(self, name, help='', type=None, argname=None,
153
 
                 short_name=None, param_name=None, custom_callback=None):
 
153
                 short_name=None, param_name=None, custom_callback=None,
 
154
                 hidden=False):
154
155
        """Make a new command option.
155
156
 
156
157
        :param name: regular name of the command, used in the double-dash
173
174
        :param custom_callback: a callback routine to be called after normal
174
175
            processing. The signature of the callback routine is
175
176
            (option, name, new_value, parser).
 
177
        :param hidden: If True, the option should be hidden in help and
 
178
            documentation.
176
179
        """
177
180
        self.name = name
178
181
        self.help = help
189
192
        else:
190
193
            self._param_name = param_name
191
194
        self.custom_callback = custom_callback
 
195
        self.hidden = hidden
192
196
 
193
197
    def short_name(self):
194
198
        if self._short_name:
208
212
        option_strings = ['--%s' % self.name]
209
213
        if short_name is not None:
210
214
            option_strings.append('-%s' % short_name)
 
215
        if self.hidden:
 
216
            help = optparse.SUPPRESS_HELP
 
217
        else:
 
218
            help = self.help
211
219
        optargfn = self.type
212
220
        if optargfn is None:
213
221
            parser.add_option(action='callback',
214
222
                              callback=self._optparse_bool_callback,
215
223
                              callback_args=(True,),
216
 
                              help=self.help,
 
224
                              help=help,
217
225
                              *option_strings)
218
226
            negation_strings = ['--%s' % self.get_negation_name()]
219
227
            parser.add_option(action='callback',
224
232
            parser.add_option(action='callback',
225
233
                              callback=self._optparse_callback,
226
234
                              type='string', metavar=self.argname.upper(),
227
 
                              help=self.help,
 
235
                              help=help,
228
236
                              default=OptionParser.DEFAULT_VALUE,
229
237
                              *option_strings)
230
238
 
250
258
        yield self.name, self.short_name(), argname, self.help
251
259
 
252
260
    def is_hidden(self, name):
253
 
        return False
 
261
        return self.hidden
254
262
 
255
263
 
256
264
class ListOption(Option):