| 11940 | } |
| 11941 | |
| 11942 | int cbm_cli_print_tool_help(const char *tool_name) { |
| 11943 | const char *schema_str = cbm_mcp_tool_input_schema(tool_name); |
| 11944 | if (!schema_str) { |
| 11945 | return CLI_ERR; |
| 11946 | } |
| 11947 | |
| 11948 | yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0); |
| 11949 | yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL; |
| 11950 | yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL; |
| 11951 | yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL; |
| 11952 | |
| 11953 | printf("Usage:\n"); |
| 11954 | printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name); |
| 11955 | printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name); |
| 11956 | printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name); |
| 11957 | printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name); |
| 11958 | |
| 11959 | printf("\nFlags:\n"); |
| 11960 | if (props && yyjson_is_obj(props)) { |
| 11961 | yyjson_obj_iter iter; |
| 11962 | yyjson_obj_iter_init(props, &iter); |
| 11963 | yyjson_val *pkey; |
| 11964 | while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) { |
| 11965 | yyjson_val *pval = yyjson_obj_iter_get_val(pkey); |
| 11966 | const char *name = yyjson_get_str(pkey); |
| 11967 | if (!name) { |
| 11968 | continue; |
| 11969 | } |
| 11970 | const char *type = "string"; |
| 11971 | const char *desc = ""; |
| 11972 | if (yyjson_is_obj(pval)) { |
| 11973 | yyjson_val *t = yyjson_obj_get(pval, "type"); |
| 11974 | if (t && yyjson_is_str(t)) { |
| 11975 | type = yyjson_get_str(t); |
| 11976 | } |
| 11977 | yyjson_val *d = yyjson_obj_get(pval, "description"); |
| 11978 | if (d && yyjson_is_str(d)) { |
| 11979 | desc = yyjson_get_str(d); |
| 11980 | } |
| 11981 | } |
| 11982 | char flag[CLI_BUF_256]; |
| 11983 | snprintf(flag, sizeof(flag), "%s", name); |
| 11984 | cli_snake_to_kebab(flag); |
| 11985 | bool req = cli_schema_required_has(required, name); |
| 11986 | printf(" --%s <%s>%s", flag, type, req ? " [required]" : ""); |
| 11987 | if (desc[0]) { |
| 11988 | printf(" %s", desc); |
| 11989 | } |
| 11990 | printf("\n"); |
| 11991 | } |
| 11992 | } |
| 11993 | |
| 11994 | if (doc) { |
| 11995 | yyjson_doc_free(doc); |
| 11996 | } |
| 11997 | return CLI_OK; |
| 11998 | } |
no test coverage detected