Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -13212,6 +13212,37 @@ static void cli_add_typed(yyjson_mut_doc *out, yyjson_mut_val *obj, const char *
arr = yyjson_mut_arr(out);
yyjson_mut_obj_add(obj, yyjson_mut_strcpy(out, key), arr);
}
/* Accept the JSON-array spelling shown by MCP schemas in addition to
* repeated flags. This keeps `--semantic-query '["a","b"]'` from
* becoming one opaque keyword while preserving the established
* `--semantic-query a --semantic-query b` form. */
yyjson_doc *array_doc =
have_value && value && value[0] == '[' ? yyjson_read(value, strlen(value), 0) : NULL;
yyjson_val *array_root = array_doc ? yyjson_doc_get_root(array_doc) : NULL;
bool string_array =
array_root && yyjson_is_arr(array_root) && yyjson_arr_size(array_root) > 0;
if (string_array) {
size_t idx;
size_t count;
yyjson_val *item;
yyjson_arr_foreach(array_root, idx, count, item) {
if (!yyjson_is_str(item)) {
string_array = false;
break;
}
}
}
if (string_array) {
size_t idx;
size_t count;
yyjson_val *item;
yyjson_arr_foreach(array_root, idx, count, item) {
yyjson_mut_arr_add_strcpy(out, arr, yyjson_get_str(item));
}
yyjson_doc_free(array_doc);
return;
}
yyjson_doc_free(array_doc);
yyjson_mut_arr_add_strcpy(out, arr, have_value ? value : "");
return;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -14141,6 +14141,16 @@ TEST(cli_build_args_json_repeated_array_issue680) {
PASS();
}

TEST(cli_build_args_json_array_literal) {
char *err = NULL;
char *argv[] = {"--semantic-query", "[\"create\",\"billing\",\"account\"]"};
char *json = cbm_cli_build_args_json("search_graph", 2, argv, &err);
ASSERT_NOT_NULL(json);
ASSERT(strstr(json, "\"semantic_query\":[\"create\",\"billing\",\"account\"]") != NULL);
free(json);
PASS();
}

/* kebab-case flag names map to snake_case JSON keys. */
TEST(cli_build_args_json_kebab_to_snake_issue680) {
char *err = NULL;
Expand Down Expand Up @@ -15244,6 +15254,7 @@ SUITE(cli) {
RUN_TEST(cli_build_args_json_bare_boolean_issue680);
RUN_TEST(cli_build_args_json_unknown_flag_rejected);
RUN_TEST(cli_build_args_json_repeated_array_issue680);
RUN_TEST(cli_build_args_json_array_literal);
RUN_TEST(cli_build_args_json_kebab_to_snake_issue680);
RUN_TEST(cli_build_args_json_key_equals_value_issue680);
RUN_TEST(cli_build_args_json_bad_positional_errors_issue680);
Expand Down
Loading