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

Function cbm_cmd_config

src/cli/cli.c:7708–7831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7706}
7707
7708int cbm_cmd_config(int argc, char **argv) {
7709 /* NULL argv with a nonzero argc previously slipped past this guard (the
7710 * inner `argv &&` shielded only the help comparison) and dereferenced
7711 * argv[0] below -- caught by the clang-analyzer lane. */
7712 if (argc == 0 || !argv || strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0) {
7713 printf("Usage: codebase-memory-mcp config <command> [args]\n\n");
7714 printf("Commands:\n");
7715 printf(" list Show all config values\n");
7716 printf(" get <key> Get a config value\n");
7717 printf(" set <key> <val> Set a config value\n");
7718 printf(" reset <key> Reset a key to default\n\n");
7719 printf("Config keys:\n");
7720 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
7721 printf(" %-25s default=%-10s %s\n", CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value,
7722 CONFIG_KEYS[i].help);
7723 }
7724 return 0;
7725 }
7726
7727 const char *home = cbm_get_home_dir();
7728 if (!home) {
7729 (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n");
7730 return CLI_TRUE;
7731 }
7732
7733 char cache_dir[CLI_BUF_1K];
7734 snprintf(cache_dir, sizeof(cache_dir), "%s", cbm_resolve_cache_dir());
7735
7736 cbm_config_t *cfg = cbm_config_open(cache_dir);
7737 if (!cfg) {
7738 (void)fprintf(stderr, "error: cannot open config database\n");
7739 return CLI_TRUE;
7740 }
7741
7742 int rc = 0;
7743 if (strcmp(argv[0], "list") == 0 || strcmp(argv[0], "ls") == 0) {
7744 printf("Configuration:\n");
7745 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
7746 char ui_value[CLI_BUF_1K];
7747 const char *shown;
7748 if (config_key_is_ui(CONFIG_KEYS[i].key)) {
7749 config_ui_read(CONFIG_KEYS[i].key, ui_value, sizeof(ui_value));
7750 shown = ui_value;
7751 } else {
7752 shown = cbm_config_get(cfg, CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value);
7753 }
7754 printf(" %-25s = %-10s\n", CONFIG_KEYS[i].key, shown);
7755 }
7756 } else if (strcmp(argv[0], "get") == 0) {
7757 if (argc < MIN_ARGC_GET) {
7758 (void)fprintf(stderr, "Usage: config get <key>\n");
7759 rc = CLI_TRUE;
7760 } else {
7761 const config_key_def_t *def = config_key_lookup(argv[CLI_SKIP_ONE]);
7762 if (!def) {
7763 config_print_unknown_key(argv[CLI_SKIP_ONE]);
7764 rc = CLI_TRUE;
7765 } else {

Callers 4

handle_subcommandFunction · 0.85
cli_config_cmd_captureFunction · 0.85

Calls 14

cbm_get_home_dirFunction · 0.85
cbm_resolve_cache_dirFunction · 0.85
cbm_config_openFunction · 0.85
config_key_is_uiFunction · 0.85
config_ui_readFunction · 0.85
cbm_config_getFunction · 0.85
config_key_lookupFunction · 0.85
config_print_unknown_keyFunction · 0.85
config_ui_writeFunction · 0.85
cbm_config_setFunction · 0.85

Tested by 2

cli_config_cmd_captureFunction · 0.68