MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cli_clients_apply_selection

Function cli_clients_apply_selection

src/cli/cli.c:9559–9596  ·  view source on GitHub ↗

Restrict `detected` to the comma-separated token list. Returns false (after * printing the vocabulary) when a token is unknown, so a typo can never be * mistaken for "that client was not installed". */

Source from the content-addressed store, hash-verified

9557 * printing the vocabulary) when a token is unknown, so a typo can never be
9558 * mistaken for "that client was not installed". */
9559static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) {
9560 bool wanted[CLI_CLIENT_COUNT];
9561 memset(wanted, 0, sizeof(wanted));
9562 char buf[CLI_BUF_1K];
9563 snprintf(buf, sizeof(buf), "%s", spec ? spec : "");
9564 char *save = NULL;
9565 for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) {
9566 while (*tok == ' ') {
9567 tok++;
9568 }
9569 size_t len = strlen(tok);
9570 while (len > 0 && tok[len - 1] == ' ') {
9571 tok[--len] = '\0';
9572 }
9573 if (!tok[0]) {
9574 continue;
9575 }
9576 bool matched = false;
9577 for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9578 if (strcmp(tok, CLI_CLIENTS[i].token) == 0) {
9579 wanted[i] = true;
9580 matched = true;
9581 break;
9582 }
9583 }
9584 if (!matched) {
9585 (void)fprintf(stderr, "error: unknown client: %s\n\n", tok);
9586 cli_clients_print_list(stderr);
9587 return false;
9588 }
9589 }
9590 for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9591 if (!wanted[i]) {
9592 *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false;
9593 }
9594 }
9595 return true;
9596}
9597
9598#ifdef CBM_CLI_ENABLE_TEST_API
9599bool cbm_cli_clients_apply_selection_for_testing(const char *spec,

Callers 3

cbm_cmd_installFunction · 0.85

Calls 1

cli_clients_print_listFunction · 0.85

Tested by

no test coverage detected