|
1 | 1 | import typer |
2 | 2 | import inquirer |
3 | 3 | import click |
| 4 | +from typing import Any |
4 | 5 | from collections.abc import Callable |
5 | 6 | from recodex_cli_lib.client import Client |
6 | 7 | from recodex_cli_lib.client_components.endpoint_resolver import EndpointResolver |
@@ -97,21 +98,27 @@ def query_list_to_dict( |
97 | 98 | presenter: str, |
98 | 99 | action: str, |
99 | 100 | query_values: list[str] |
100 | | -) -> dict[str, str]: |
| 101 | +) -> dict[str, Any]: |
101 | 102 | query_dict = {} |
102 | 103 | for query_value in query_values: |
103 | | - if query_value.count("=") != 1: |
| 104 | + if query_value.count("=") < 1: |
104 | 105 | raise Exception("The query values need to be in <name=value> format.") |
105 | 106 |
|
106 | | - name, value = query_value.split("=") |
| 107 | + # there can be '=' in the value, so split by the first one |
| 108 | + split_pos = query_value.find("=") |
| 109 | + name = query_value[0: split_pos] |
| 110 | + value = query_value[split_pos + 1:] |
| 111 | + |
107 | 112 | query_param = endpoint_resolver.get_query_param(presenter, action, name) |
108 | 113 | if not query_param or name != query_param["python_name"]: |
109 | 114 | raise Exception(f"Unknown QUERY parameter: {name}.") |
110 | 115 |
|
111 | | - # handle arrays |
112 | | - if query_param["schema"]["type"] == "array": |
113 | | - # arrays are delimited with commas |
114 | | - value = value.split(",") |
| 116 | + # handle arrays and objects |
| 117 | + if query_param["schema"]["type"] == "array" or query_param["schema"]["type"] == "object": |
| 118 | + try: |
| 119 | + value = cmd_utils.parse_json(value) |
| 120 | + except: |
| 121 | + raise Exception(f"The QUERY parameter '{name}' is not a valid JSON array or object.") |
115 | 122 |
|
116 | 123 | query_dict[name] = value |
117 | 124 | return query_dict |
|
0 commit comments