From 0a42bc3e82e2fe2987d7a536067f346af4443a9c Mon Sep 17 00:00:00 2001 From: xiaofanzhou Date: Fri, 9 Apr 2021 13:06:37 +0800 Subject: [PATCH 1/2] add allowed values information when enum validation fails --- src/azure-cli-core/azure/cli/core/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/parser.py b/src/azure-cli-core/azure/cli/core/parser.py index a0c194ffba2..dab666ec5a2 100644 --- a/src/azure-cli-core/azure/cli/core/parser.py +++ b/src/azure-cli-core/azure/cli/core/parser.py @@ -497,8 +497,8 @@ def _check_value(self, action, value): # pylint: disable=too-many-statements, t else: # `command_source` indicates command values have been parsed, value is an argument parameter = action.option_strings[0] if action.option_strings else action.dest - error_msg = "{prog}: '{value}' is not a valid value for '{param}'.".format( - prog=self.prog, value=value, param=parameter) + error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choice}.".format( + prog=self.prog, value=value, param=parameter, choice=', '.join(sorted([str(x) for x in action.choices]))) candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) az_error = InvalidArgumentValueError(error_msg) From 89d5caf9b8b779c90161e47077ac5e93c81fbb56 Mon Sep 17 00:00:00 2001 From: xiaofanzhou Date: Fri, 9 Apr 2021 15:47:26 +0800 Subject: [PATCH 2/2] lint --- src/azure-cli-core/azure/cli/core/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/parser.py b/src/azure-cli-core/azure/cli/core/parser.py index dab666ec5a2..12d25aa3cf2 100644 --- a/src/azure-cli-core/azure/cli/core/parser.py +++ b/src/azure-cli-core/azure/cli/core/parser.py @@ -497,8 +497,8 @@ def _check_value(self, action, value): # pylint: disable=too-many-statements, t else: # `command_source` indicates command values have been parsed, value is an argument parameter = action.option_strings[0] if action.option_strings else action.dest - error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choice}.".format( - prog=self.prog, value=value, param=parameter, choice=', '.join(sorted([str(x) for x in action.choices]))) + error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choices}.".format( + prog=self.prog, value=value, param=parameter, choices=', '.join([str(x) for x in action.choices])) candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) az_error = InvalidArgumentValueError(error_msg)