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

Function cbm_cmd_config

src/cli/cli.c:6612–6702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6610}
6611
6612int cbm_cmd_config(int argc, char **argv) {
6613 /* NULL argv with a nonzero argc previously slipped past this guard (the
6614 * inner `argv &&` shielded only the help comparison) and dereferenced
6615 * argv[0] below -- caught by the clang-analyzer lane. */
6616 if (argc == 0 || !argv || strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0) {
6617 printf("Usage: codebase-memory-mcp config <command> [args]\n\n");
6618 printf("Commands:\n");
6619 printf(" list Show all config values\n");
6620 printf(" get <key> Get a config value\n");
6621 printf(" set <key> <val> Set a config value\n");
6622 printf(" reset <key> Reset a key to default\n\n");
6623 printf("Config keys:\n");
6624 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6625 printf(" %-25s default=%-10s %s\n", CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value,
6626 CONFIG_KEYS[i].help);
6627 }
6628 return 0;
6629 }
6630
6631 const char *home = cbm_get_home_dir();
6632 if (!home) {
6633 (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n");
6634 return CLI_TRUE;
6635 }
6636
6637 char cache_dir[CLI_BUF_1K];
6638 snprintf(cache_dir, sizeof(cache_dir), "%s", cbm_resolve_cache_dir());
6639
6640 cbm_config_t *cfg = cbm_config_open(cache_dir);
6641 if (!cfg) {
6642 (void)fprintf(stderr, "error: cannot open config database\n");
6643 return CLI_TRUE;
6644 }
6645
6646 int rc = 0;
6647 if (strcmp(argv[0], "list") == 0 || strcmp(argv[0], "ls") == 0) {
6648 printf("Configuration:\n");
6649 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6650 printf(" %-25s = %-10s\n", CONFIG_KEYS[i].key,
6651 cbm_config_get(cfg, CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value));
6652 }
6653 } else if (strcmp(argv[0], "get") == 0) {
6654 if (argc < MIN_ARGC_GET) {
6655 (void)fprintf(stderr, "Usage: config get <key>\n");
6656 rc = CLI_TRUE;
6657 } else {
6658 const config_key_def_t *def = config_key_lookup(argv[CLI_SKIP_ONE]);
6659 if (!def) {
6660 config_print_unknown_key(argv[CLI_SKIP_ONE]);
6661 rc = CLI_TRUE;
6662 } else {
6663 /* Stored value or the key's real default — the same fallback
6664 * the runtime readers use. `""` here was #1522's bug 2: every
6665 * unset key read as empty with exit 0. */
6666 printf("%s\n", cbm_config_get(cfg, def->key, def->default_value));
6667 }
6668 }
6669 } 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