From 7c7d7741c6b380b9fdb94e0789f322b1a086f8cc Mon Sep 17 00:00:00 2001 From: Vipul Date: Tue, 29 Oct 2024 10:04:16 -0700 Subject: [PATCH] Simplify cmd parsing logic --- ads/aqua/common/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ads/aqua/common/utils.py b/ads/aqua/common/utils.py index 8615728db..7a0d9d46b 100644 --- a/ads/aqua/common/utils.py +++ b/ads/aqua/common/utils.py @@ -1114,12 +1114,16 @@ def parse_cmd_var(cmd_list: List[str]) -> dict: """Helper functions that parses a list into a key-value dictionary. The list contains keys separated by the prefix '--' and the value of the key is the subsequent element. """ - it = iter(cmd_list) - return { - key: next(it, None) if not key.startswith("--") else next(it, None) - for key in it - if key.startswith("--") - } + parsed_cmd = {} + + for i, cmd in enumerate(cmd_list): + if cmd.startswith("--"): + if i + 1 < len(cmd_list) and not cmd_list[i + 1].startswith("--"): + parsed_cmd[cmd] = cmd_list[i + 1] + i += 1 + else: + parsed_cmd[cmd] = None + return parsed_cmd def validate_cmd_var(cmd_var: List[str], overrides: List[str]) -> List[str]: