| 4683 | } |
| 4684 | |
| 4685 | int cbm_cli_print_tool_help(const char *tool_name) { |
| 4686 | const char *schema_str = cbm_mcp_tool_input_schema(tool_name); |
| 4687 | if (!schema_str) { |
| 4688 | return CLI_ERR; |
| 4689 | } |
| 4690 | |
| 4691 | yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0); |
| 4692 | yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL; |
| 4693 | yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL; |
| 4694 | yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL; |
| 4695 | |
| 4696 | printf("Usage:\n"); |
| 4697 | printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name); |
| 4698 | printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name); |
| 4699 | printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name); |
| 4700 | printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name); |
| 4701 | |
| 4702 | printf("\nFlags:\n"); |
| 4703 | if (props && yyjson_is_obj(props)) { |
| 4704 | yyjson_obj_iter iter; |
| 4705 | yyjson_obj_iter_init(props, &iter); |
| 4706 | yyjson_val *pkey; |
| 4707 | while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) { |
| 4708 | yyjson_val *pval = yyjson_obj_iter_get_val(pkey); |
| 4709 | const char *name = yyjson_get_str(pkey); |
| 4710 | if (!name) { |
| 4711 | continue; |
| 4712 | } |
| 4713 | const char *type = "string"; |
| 4714 | const char *desc = ""; |
| 4715 | if (yyjson_is_obj(pval)) { |
| 4716 | yyjson_val *t = yyjson_obj_get(pval, "type"); |
| 4717 | if (t && yyjson_is_str(t)) { |
| 4718 | type = yyjson_get_str(t); |
| 4719 | } |
| 4720 | yyjson_val *d = yyjson_obj_get(pval, "description"); |
| 4721 | if (d && yyjson_is_str(d)) { |
| 4722 | desc = yyjson_get_str(d); |
| 4723 | } |
| 4724 | } |
| 4725 | char flag[CLI_BUF_256]; |
| 4726 | snprintf(flag, sizeof(flag), "%s", name); |
| 4727 | cli_snake_to_kebab(flag); |
| 4728 | bool req = cli_schema_required_has(required, name); |
| 4729 | printf(" --%s <%s>%s", flag, type, req ? " [required]" : ""); |
| 4730 | if (desc[0]) { |
| 4731 | printf(" %s", desc); |
| 4732 | } |
| 4733 | printf("\n"); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | if (doc) { |
| 4738 | yyjson_doc_free(doc); |
| 4739 | } |
| 4740 | return CLI_OK; |
| 4741 | } |
no test coverage detected