From 552328b86023537253ccfd1332b0174a227e5685 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 24 Oct 2012 04:08:42 +0200 Subject: [PATCH] cli: Use callback for --priority If the option is used elsewhere, the numeric value is directly available. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Bernardo Dal Seno <bdalseno@google.com> --- lib/cli.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index f0e8a167e..c1b3e2453 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1335,9 +1335,21 @@ PRIMARY_IP_VERSION_OPT = \ constants.IP6_VERSION), help="Cluster-wide IP version for primary IP") + +def _PriorityOptionCb(option, _, value, parser): + """Callback for processing C{--priority} option. + + """ + value = _PRIONAME_TO_VALUE[value] + + setattr(parser.values, option.dest, value) + + PRIORITY_OPT = cli_option("--priority", default=None, dest="priority", metavar="|".join(name for name, _ in _PRIORITY_NAMES), choices=_PRIONAME_TO_VALUE.keys(), + action="callback", type="choice", + callback=_PriorityOptionCb, help="Priority for opcode processing") HID_OS_OPT = cli_option("--hidden", dest="hidden", @@ -2097,7 +2109,7 @@ def SetGenericOpcodeOpts(opcode_list, options): if hasattr(options, "dry_run"): op.dry_run = options.dry_run if getattr(options, "priority", None) is not None: - op.priority = _PRIONAME_TO_VALUE[options.priority] + op.priority = options.priority def GetClient(query=False): -- GitLab