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

Function cbm_cmd_config

src/cli/cli.c:6836–6953  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6834}
6835
6836int cbm_cmd_config(int argc, char **argv) {
6837 /* NULL argv with a nonzero argc previously slipped past this guard (the
6838 * inner `argv &&` shielded only the help comparison) and dereferenced
6839 * argv[0] below -- caught by the clang-analyzer lane. */
6840 if (argc == 0 || !argv || strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0) {
6841 printf("Usage: codebase-memory-mcp config <command> [args]\n\n");
6842 printf("Commands:\n");
6843 printf(" list Show all config values\n");
6844 printf(" get <key> Get a config value\n");
6845 printf(" set <key> <val> Set a config value\n");
6846 printf(" reset <key> Reset a key to default\n\n");
6847 printf("Config keys:\n");
6848 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6849 printf(" %-25s default=%-10s %s\n", CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value,
6850 CONFIG_KEYS[i].help);
6851 }
6852 return 0;
6853 }
6854
6855 const char *home = cbm_get_home_dir();
6856 if (!home) {
6857 (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n");
6858 return CLI_TRUE;
6859 }
6860
6861 char cache_dir[CLI_BUF_1K];
6862 snprintf(cache_dir, sizeof(cache_dir), "%s", cbm_resolve_cache_dir());
6863
6864 cbm_config_t *cfg = cbm_config_open(cache_dir);
6865 if (!cfg) {
6866 (void)fprintf(stderr, "error: cannot open config database\n");
6867 return CLI_TRUE;
6868 }
6869
6870 int rc = 0;
6871 if (strcmp(argv[0], "list") == 0 || strcmp(argv[0], "ls") == 0) {
6872 printf("Configuration:\n");
6873 for (size_t i = 0; i < sizeof(CONFIG_KEYS) / sizeof(CONFIG_KEYS[0]); i++) {
6874 char ui_value[CLI_BUF_1K];
6875 const char *shown;
6876 if (config_key_is_ui(CONFIG_KEYS[i].key)) {
6877 config_ui_read(CONFIG_KEYS[i].key, ui_value, sizeof(ui_value));
6878 shown = ui_value;
6879 } else {
6880 shown = cbm_config_get(cfg, CONFIG_KEYS[i].key, CONFIG_KEYS[i].default_value);
6881 }
6882 printf(" %-25s = %-10s\n", CONFIG_KEYS[i].key, shown);
6883 }
6884 } else if (strcmp(argv[0], "get") == 0) {
6885 if (argc < MIN_ARGC_GET) {
6886 (void)fprintf(stderr, "Usage: config get <key>\n");
6887 rc = CLI_TRUE;
6888 } else {
6889 const config_key_def_t *def = config_key_lookup(argv[CLI_SKIP_ONE]);
6890 if (!def) {
6891 config_print_unknown_key(argv[CLI_SKIP_ONE]);
6892 rc = CLI_TRUE;
6893 } else {

Callers 2

handle_subcommandFunction · 0.85
cli_config_cmd_captureFunction · 0.85

Calls 12

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
cbm_config_deleteFunction · 0.85
cbm_config_closeFunction · 0.85

Tested by 1

cli_config_cmd_captureFunction · 0.68