| 11596 | } |
| 11597 | |
| 11598 | int cbm_cmd_uninstall(int argc, char **argv) { |
| 11599 | /* `uninstall --help` used to UNINSTALL. |
| 11600 | * |
| 11601 | * The top-level dispatcher matches the subcommand at argv[1] and hands the |
| 11602 | * rest here, so its own --help check never sees argv[2]. Nothing downstream |
| 11603 | * looked either, and --help is the one flag a person types precisely |
| 11604 | * BECAUSE they are not sure what a command does. It removed the binary and |
| 11605 | * every agent configuration (#1038). |
| 11606 | * |
| 11607 | * Checked before parse_auto_answer so a `-y` sitting elsewhere on the line |
| 11608 | * cannot auto-confirm the destruction we are trying to prevent. */ |
| 11609 | for (int i = 0; i < argc; i++) { |
| 11610 | if (argv && argv[i] && (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)) { |
| 11611 | printf("Usage: codebase-memory-mcp uninstall [options]\n\n" |
| 11612 | "Removes the codebase-memory-mcp binary, its agent configurations and,\n" |
| 11613 | "with confirmation, its indexes. THIS IS DESTRUCTIVE.\n\n" |
| 11614 | "Options:\n" |
| 11615 | " --dry-run Show what would be removed, change nothing\n" |
| 11616 | " --dir=PATH Uninstall from a custom install directory\n" |
| 11617 | " -y, --yes Do not prompt for confirmation\n" |
| 11618 | " -h, --help Show this help and exit\n\n" |
| 11619 | "Run with --dry-run first if you are unsure.\n"); |
| 11620 | return CLI_OK; |
| 11621 | } |
| 11622 | } |
| 11623 | parse_auto_answer(argc, argv); |
| 11624 | bool dry_run = false; |
| 11625 | /* An install into a custom --dir must be removable from that same dir: |
| 11626 | * without this, anyone who installed outside ~/.local/bin has no supported |
| 11627 | * uninstall path at all. Mirrors cbm_cmd_install's parsing. */ |
| 11628 | const char *requested_bin_dir = NULL; |
| 11629 | for (int i = 0; i < argc; i++) { |
| 11630 | /* The public command dispatcher passes option-only argv, while the |
| 11631 | * long-standing direct API/tests include the subcommand at argv[0]. */ |
| 11632 | if (i == 0 && strcmp(argv[i], "uninstall") == 0) { |
| 11633 | continue; |
| 11634 | } |
| 11635 | if (strcmp(argv[i], "--dry-run") == 0) { |
| 11636 | dry_run = true; |
| 11637 | } else if (strncmp(argv[i], "--dir=", SLEN("--dir=")) == 0) { |
| 11638 | requested_bin_dir = argv[i] + SLEN("--dir="); |
| 11639 | if (!requested_bin_dir[0]) { |
| 11640 | (void)fprintf(stderr, "error: --dir requires a non-empty path\n"); |
| 11641 | return CLI_TRUE; |
| 11642 | } |
| 11643 | } else if (strcmp(argv[i], "--dir") == 0) { |
| 11644 | if (i + 1 >= argc || !argv[i + 1] || !argv[i + 1][0] || argv[i + 1][0] == '-') { |
| 11645 | (void)fprintf(stderr, "error: --dir requires a non-empty path\n"); |
| 11646 | return CLI_TRUE; |
| 11647 | } |
| 11648 | requested_bin_dir = argv[++i]; |
| 11649 | } else if (strcmp(argv[i], "-y") != 0 && strcmp(argv[i], "--yes") != 0 && |
| 11650 | strcmp(argv[i], "-n") != 0 && strcmp(argv[i], "--no") != 0) { |
| 11651 | (void)fprintf(stderr, "error: unknown uninstall option: %s\n", argv[i]); |
| 11652 | return CLI_TRUE; |
| 11653 | } |
| 11654 | } |
| 11655 |
no test coverage detected