Revision bf5338b3 lib/cli.py

b/lib/cli.py
29 29
import logging
30 30
import errno
31 31
import itertools
32
import optparse
33 32
from cStringIO import StringIO
34 33

  
35 34
from ganeti import utils
......
44 43
from ganeti import netutils
45 44
from ganeti import qlang
46 45

  
47
from optparse import (TitledHelpFormatter,
46
from optparse import (OptionParser, TitledHelpFormatter,
48 47
                      Option, OptionValueError)
49 48

  
50 49

  
......
1334 1333
    cmd = aliases[cmd]
1335 1334

  
1336 1335
  func, args_def, parser_opts, usage, description = commands[cmd]
1337
  parser = CustomOptionParser(option_list=parser_opts + COMMON_OPTS,
1338
                              description=description,
1339
                              formatter=TitledHelpFormatter(),
1340
                              usage="%%prog %s %s" % (cmd, usage))
1336
  parser = OptionParser(option_list=parser_opts + COMMON_OPTS,
1337
                        description=description,
1338
                        formatter=TitledHelpFormatter(),
1339
                        usage="%%prog %s %s" % (cmd, usage))
1341 1340
  parser.disable_interspersed_args()
1342 1341
  options, args = parser.parse_args()
1343 1342

  
......
1347 1346
  return func, options, args
1348 1347

  
1349 1348

  
1350
class CustomOptionParser(optparse.OptionParser):
1351
  def _match_long_opt(self, opt):
1352
    """Override C{OptionParser}'s function for matching long options.
1353

  
1354
    The default implementation does prefix-based abbreviation matching. We
1355
    disable such behaviour as it can can lead to confusing conflicts (e.g.
1356
    C{--force} and C{--force-multi}).
1357

  
1358
    """
1359
    if opt in self._long_opt:
1360
      return opt
1361
    else:
1362
      raise optparse.BadOptionError(opt)
1363

  
1364

  
1365 1349
def _CheckArguments(cmd, args_def, args):
1366 1350
  """Verifies the arguments using the argument definition.
1367 1351

  

Also available in: Unified diff