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

Function cli_clients_apply_selection

src/cli/cli.c:9394–9431  ·  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

9392 * printing the vocabulary) when a token is unknown, so a typo can never be
9393 * mistaken for "that client was not installed". */
9394static bool cli_clients_apply_selection(const char *spec, cbm_detected_agents_t *detected) {
9395 bool wanted[CLI_CLIENT_COUNT];
9396 memset(wanted, 0, sizeof(wanted));
9397 char buf[CLI_BUF_1K];
9398 snprintf(buf, sizeof(buf), "%s", spec ? spec : "");
9399 char *save = NULL;
9400 for (char *tok = strtok_r(buf, ",", &save); tok; tok = strtok_r(NULL, ",", &save)) {
9401 while (*tok == ' ') {
9402 tok++;
9403 }
9404 size_t len = strlen(tok);
9405 while (len > 0 && tok[len - 1] == ' ') {
9406 tok[--len] = '\0';
9407 }
9408 if (!tok[0]) {
9409 continue;
9410 }
9411 bool matched = false;
9412 for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9413 if (strcmp(tok, CLI_CLIENTS[i].token) == 0) {
9414 wanted[i] = true;
9415 matched = true;
9416 break;
9417 }
9418 }
9419 if (!matched) {
9420 (void)fprintf(stderr, "error: unknown client: %s\n\n", tok);
9421 cli_clients_print_list(stderr);
9422 return false;
9423 }
9424 }
9425 for (size_t i = 0; i < CLI_CLIENT_COUNT; i++) {
9426 if (!wanted[i]) {
9427 *(bool *)((char *)detected + CLI_CLIENTS[i].offset) = false;
9428 }
9429 }
9430 return true;
9431}
9432
9433#ifdef CBM_CLI_ENABLE_TEST_API
9434bool 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