Skip to content

Commit

Permalink
Simplify cmd parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
VipulMascarenhas committed Oct 29, 2024
1 parent 80cb16c commit 7c7d774
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ads/aqua/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 7c7d774

Please sign in to comment.