| 14321 | } |
| 14322 | |
| 14323 | int cbm_cli_print_tool_help(const char *tool_name) { |
| 14324 | const char *schema_str = cbm_mcp_tool_input_schema(tool_name); |
| 14325 | if (!schema_str) { |
| 14326 | return CLI_ERR; |
| 14327 | } |
| 14328 | |
| 14329 | yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0); |
| 14330 | yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL; |
| 14331 | yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL; |
| 14332 | yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL; |
| 14333 | |
| 14334 | printf("Usage:\n"); |
| 14335 | printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name); |
| 14336 | printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name); |
| 14337 | printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name); |
| 14338 | printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name); |
| 14339 | |
| 14340 | printf("\nFlags:\n"); |
| 14341 | if (props && yyjson_is_obj(props)) { |
| 14342 | yyjson_obj_iter iter; |
| 14343 | yyjson_obj_iter_init(props, &iter); |
| 14344 | yyjson_val *pkey; |
| 14345 | while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) { |
| 14346 | yyjson_val *pval = yyjson_obj_iter_get_val(pkey); |
| 14347 | const char *name = yyjson_get_str(pkey); |
| 14348 | if (!name) { |
| 14349 | continue; |
| 14350 | } |
| 14351 | const char *type = "string"; |
| 14352 | const char *desc = ""; |
| 14353 | yyjson_val *choices = NULL; |
| 14354 | yyjson_val *default_value = NULL; |
| 14355 | if (yyjson_is_obj(pval)) { |
| 14356 | yyjson_val *t = yyjson_obj_get(pval, "type"); |
| 14357 | if (t && yyjson_is_str(t)) { |
| 14358 | type = yyjson_get_str(t); |
| 14359 | } |
| 14360 | yyjson_val *d = yyjson_obj_get(pval, "description"); |
| 14361 | if (d && yyjson_is_str(d)) { |
| 14362 | desc = yyjson_get_str(d); |
| 14363 | } |
| 14364 | choices = yyjson_obj_get(pval, "enum"); |
| 14365 | default_value = yyjson_obj_get(pval, "default"); |
| 14366 | } |
| 14367 | char flag[CLI_BUF_256]; |
| 14368 | snprintf(flag, sizeof(flag), "%s", name); |
| 14369 | cli_snake_to_kebab(flag); |
| 14370 | bool req = cli_schema_required_has(required, name); |
| 14371 | printf(" --%s <", flag); |
| 14372 | if (choices && yyjson_is_arr(choices) && yyjson_arr_size(choices) > 0) { |
| 14373 | size_t idx; |
| 14374 | size_t max; |
| 14375 | yyjson_val *choice; |
| 14376 | yyjson_arr_foreach(choices, idx, max, choice) { |
| 14377 | if (idx > 0) { |
| 14378 | fputc('|', stdout); |
| 14379 | } |
| 14380 | cli_print_schema_value(choice); |