Commit 232aab3f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli: Disable abbreviation matching for options

Python's “optparse” module does option name prefix matching by default.
Since this can lead to confusing behaviour, e.g. by specifying “--force”
for a command which only has a “--force-multi” option, this patch
disables the prefix matching.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarGuido Trotter <>
parent c52d91e6
......@@ -29,6 +29,7 @@ import time
import logging
import errno
import itertools
import optparse
from cStringIO import StringIO
from ganeti import utils
......@@ -43,7 +44,7 @@ from ganeti import compat
from ganeti import netutils
from ganeti import qlang
from optparse import (OptionParser, TitledHelpFormatter,
from optparse import (TitledHelpFormatter,
Option, OptionValueError)
......@@ -1333,10 +1334,10 @@ def _ParseArgs(argv, commands, aliases):
cmd = aliases[cmd]
func, args_def, parser_opts, usage, description = commands[cmd]
parser = OptionParser(option_list=parser_opts + COMMON_OPTS,
usage="%%prog %s %s" % (cmd, usage))
parser = CustomOptionParser(option_list=parser_opts + COMMON_OPTS,
usage="%%prog %s %s" % (cmd, usage))
options, args = parser.parse_args()
......@@ -1346,6 +1347,21 @@ def _ParseArgs(argv, commands, aliases):
return func, options, args
class CustomOptionParser(optparse.OptionParser):
def _match_long_opt(self, opt):
"""Override C{OptionParser}'s function for matching long options.
The default implementation does prefix-based abbreviation matching. We
disable such behaviour as it can can lead to confusing conflicts (e.g.
C{--force} and C{--force-multi}).
if opt in self._long_opt:
return opt
raise optparse.BadOptionError(opt)
def _CheckArguments(cmd, args_def, args):
"""Verifies the arguments using the argument definition.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment