| 11973 | #endif /* CBM_CLI_ENABLE_TEST_API */ |
| 11974 | |
| 11975 | int cbm_cmd_update(int argc, char **argv) { |
| 11976 | parse_auto_answer(argc, argv); |
| 11977 | |
| 11978 | bool dry_run = false; |
| 11979 | bool force = false; |
| 11980 | bool legacy_variant_flag = false; |
| 11981 | for (int i = 0; i < argc; i++) { |
| 11982 | if (strcmp(argv[i], "--dry-run") == 0) { |
| 11983 | dry_run = true; |
| 11984 | } else if (strcmp(argv[i], "--force") == 0) { |
| 11985 | force = true; |
| 11986 | } else if (strcmp(argv[i], "--ui") == 0 || strcmp(argv[i], "--standard") == 0) { |
| 11987 | /* v0.10.2 deleted the ui/standard chooser and, with it, these flags — |
| 11988 | * which turned `update --ui` from a working command into a hard |
| 11989 | * error for everyone who had it in a script, an alias, or muscle |
| 11990 | * memory (#1544). Removing a CHOICE is fine; removing the WORDS |
| 11991 | * people type is a break we owe them nothing for. Accept both, |
| 11992 | * ignore them, and say once why they no longer mean anything. */ |
| 11993 | legacy_variant_flag = true; |
| 11994 | } else if (strcmp(argv[i], "-y") != 0 && strcmp(argv[i], "--yes") != 0 && |
| 11995 | strcmp(argv[i], "-n") != 0 && strcmp(argv[i], "--no") != 0) { |
| 11996 | (void)fprintf(stderr, "error: unknown update option: %s\n", argv[i]); |
| 11997 | return CLI_TRUE; |
| 11998 | } |
| 11999 | } |
| 12000 | if (legacy_variant_flag) { |
| 12001 | (void)fprintf(stderr, "note: --ui/--standard are accepted but no longer do anything; since " |
| 12002 | "v0.10.0 there is one build per platform and it always includes the " |
| 12003 | "graph UI.\n"); |
| 12004 | } |
| 12005 | |
| 12006 | /* #1566: we cannot update a binary a package manager owns, and pretending |
| 12007 | * otherwise is the dishonest-success pattern this project keeps fixing: |
| 12008 | * reporting that an update ran while changing nothing leaves the user |
| 12009 | * convinced they are current. Refuse, and name the command that WILL work. */ |
| 12010 | { |
| 12011 | char self_path[CLI_BUF_1K] = {0}; |
| 12012 | const char *home = cbm_get_home_dir(); |
| 12013 | bool self_exact = home && cbm_detect_self_path(self_path, sizeof(self_path), home); |
| 12014 | char managed_dir[CLI_BUF_1K] = {0}; |
| 12015 | if (self_exact && home) { |
| 12016 | snprintf(managed_dir, sizeof(managed_dir), "%s/.local/bin", home); |
| 12017 | } |
| 12018 | if (self_exact && cli_binary_is_externally_managed(self_path, true, managed_dir)) { |
| 12019 | const char *manager = cli_external_manager_name(self_path); |
| 12020 | (void)fprintf(stderr, |
| 12021 | "error: this binary is managed by %s, so `update` cannot replace it:\n" |
| 12022 | " %s\n", |
| 12023 | manager ? manager : "another installer", self_path); |
| 12024 | if (manager && strcmp(manager, "mise") == 0) { |
| 12025 | (void)fprintf(stderr, " update it with: mise upgrade codebase-memory-mcp\n"); |
| 12026 | } else if (manager && strcmp(manager, "Homebrew") == 0) { |
| 12027 | (void)fprintf(stderr, " update it with: brew upgrade codebase-memory-mcp\n"); |
| 12028 | } else { |
| 12029 | (void)fprintf(stderr, " update it through whichever tool installed it.\n"); |
| 12030 | } |
| 12031 | (void)fprintf(stderr, " to refresh only the agent configurations, run: " |
| 12032 | "codebase-memory-mcp install --skip-binary\n"); |
no test coverage detected