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

Function cbm_cmd_config

src/cli/cli.c:6550–6640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6548}
6549
6550int cbm_cmd_config(int argc, char **argv) {
6551 /* NULL argv with a nonzero argc previously slipped past this guard (the
6552 * inner `argv &&` shielded only the help comparison) and dereferenced
6553 * argv[0] below -- caught by the clang-analyzer lane. */
6554 if (argc == 0 || !argv || strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0) {
6555 printf("Usage: codebase-memory-mcp config <command> [args]\n\n");
6556 printf("Commands:\n");
6557 printf(" list Show all config values\n");
6558 printf(" get <key> Get a config value\n");
6559 printf(" set <key> <val> Set a config value\n");
6560 printf(" reset <key> Reset a key to default\n\n");
6561 printf("Config keys:\n");
6562 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6563 printf(" %-25s default=%-10s %s\n", CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value,
6564 CONFIG_KEYS[i].help);
6565 }
6566 return 0;
6567 }
6568
6569 const char *home = cbm_get_home_dir();
6570 if (!home) {
6571 (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n");
6572 return CLI_TRUE;
6573 }
6574
6575 char cache_dir[CLI_BUF_1K];
6576 snprintf(cache_dir, sizeof(cache_dir), "%s", cbm_resolve_cache_dir());
6577
6578 cbm_config_t *cfg = cbm_config_open(cache_dir);
6579 if (!cfg) {
6580 (void)fprintf(stderr, "error: cannot open config database\n");
6581 return CLI_TRUE;
6582 }
6583
6584 int rc = 0;
6585 if (strcmp(argv[0], "list") == 0 || strcmp(argv[0], "ls") == 0) {
6586 printf("Configuration:\n");
6587 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6588 printf(" %-25s = %-10s\n", CONFIG_KEYS[i].key,
6589 cbm_config_get(cfg, CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value));
6590 }
6591 } else if (strcmp(argv[0], "get") == 0) {
6592 if (argc < MIN_ARGC_GET) {
6593 (void)fprintf(stderr, "Usage: config get <key>\n");
6594 rc = CLI_TRUE;
6595 } else {
6596 const config_key_def_t *def = config_key_lookup(argv[CLI_SKIP_ONE]);
6597 if (!def) {
6598 config_print_unknown_key(argv[CLI_SKIP_ONE]);
6599 rc = CLI_TRUE;
6600 } else {
6601 /* Stored value or the key's real default — the same fallback
6602 * the runtime readers use. `""` here was #1522's bug 2: every
6603 * unset key read as empty with exit 0. */
6604 printf("%s\n", cbm_config_get(cfg, def->key, def->default_value));
6605 }
6606 }
6607 } else if (strcmp(argv[0], "set") == 0) {

Callers 2

handle_subcommandFunction · 0.85
cli_config_cmd_captureFunction · 0.85

Calls 9

cbm_get_home_dirFunction · 0.85
cbm_resolve_cache_dirFunction · 0.85
cbm_config_openFunction · 0.85
cbm_config_getFunction · 0.85
config_key_lookupFunction · 0.85
config_print_unknown_keyFunction · 0.85
cbm_config_setFunction · 0.85
cbm_config_deleteFunction · 0.85
cbm_config_closeFunction · 0.85

Tested by 1

cli_config_cmd_captureFunction · 0.68