| 13927 | } |
| 13928 | |
| 13929 | int cbm_cli_print_tool_help(const char *tool_name) { |
| 13930 | const char *schema_str = cbm_mcp_tool_input_schema(tool_name); |
| 13931 | if (!schema_str) { |
| 13932 | return CLI_ERR; |
| 13933 | } |
| 13934 | |
| 13935 | yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0); |
| 13936 | yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL; |
| 13937 | yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL; |
| 13938 | yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL; |
| 13939 | |
| 13940 | printf("Usage:\n"); |
| 13941 | printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name); |
| 13942 | printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name); |
| 13943 | printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name); |
| 13944 | printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name); |
| 13945 | |
| 13946 | printf("\nFlags:\n"); |
| 13947 | if (props && yyjson_is_obj(props)) { |
| 13948 | yyjson_obj_iter iter; |
| 13949 | yyjson_obj_iter_init(props, &iter); |
| 13950 | yyjson_val *pkey; |
| 13951 | while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) { |
| 13952 | yyjson_val *pval = yyjson_obj_iter_get_val(pkey); |
| 13953 | const char *name = yyjson_get_str(pkey); |
| 13954 | if (!name) { |
| 13955 | continue; |
| 13956 | } |
| 13957 | const char *type = "string"; |
| 13958 | const char *desc = ""; |
| 13959 | yyjson_val *choices = NULL; |
| 13960 | yyjson_val *default_value = NULL; |
| 13961 | if (yyjson_is_obj(pval)) { |
| 13962 | yyjson_val *t = yyjson_obj_get(pval, "type"); |
| 13963 | if (t && yyjson_is_str(t)) { |
| 13964 | type = yyjson_get_str(t); |
| 13965 | } |
| 13966 | yyjson_val *d = yyjson_obj_get(pval, "description"); |
| 13967 | if (d && yyjson_is_str(d)) { |
| 13968 | desc = yyjson_get_str(d); |
| 13969 | } |
| 13970 | choices = yyjson_obj_get(pval, "enum"); |
| 13971 | default_value = yyjson_obj_get(pval, "default"); |
| 13972 | } |
| 13973 | char flag[CLI_BUF_256]; |
| 13974 | snprintf(flag, sizeof(flag), "%s", name); |
| 13975 | cli_snake_to_kebab(flag); |
| 13976 | bool req = cli_schema_required_has(required, name); |
| 13977 | printf(" --%s <", flag); |
| 13978 | if (choices && yyjson_is_arr(choices) && yyjson_arr_size(choices) > 0) { |
| 13979 | size_t idx; |
| 13980 | size_t max; |
| 13981 | yyjson_val *choice; |
| 13982 | yyjson_arr_foreach(choices, idx, max, choice) { |
| 13983 | if (idx > 0) { |
| 13984 | fputc('|', stdout); |
| 13985 | } |
| 13986 | cli_print_schema_value(choice); |