| 9410 | } |
| 9411 | |
| 9412 | int cbm_cmd_install(int argc, char **argv) { |
| 9413 | parse_auto_answer(argc, argv); |
| 9414 | bool dry_run = false; |
| 9415 | bool force = false; |
| 9416 | bool plan = false; |
| 9417 | bool reset_indexes = false; |
| 9418 | bool skip_config = false; |
| 9419 | const char *requested_bin_dir = NULL; |
| 9420 | for (int i = 0; i < argc; i++) { |
| 9421 | if (strcmp(argv[i], "--dry-run") == 0) { |
| 9422 | dry_run = true; |
| 9423 | } else if (strcmp(argv[i], "--force") == 0) { |
| 9424 | force = true; |
| 9425 | } else if (strcmp(argv[i], "--plan") == 0) { |
| 9426 | plan = true; |
| 9427 | } else if (strcmp(argv[i], "--reset-indexes") == 0) { |
| 9428 | reset_indexes = true; |
| 9429 | } else if (strcmp(argv[i], "--skip-config") == 0) { |
| 9430 | skip_config = true; |
| 9431 | } else if (strncmp(argv[i], "--dir=", SLEN("--dir=")) == 0) { |
| 9432 | requested_bin_dir = argv[i] + SLEN("--dir="); |
| 9433 | if (!requested_bin_dir[0]) { |
| 9434 | (void)fprintf(stderr, "error: --dir requires a non-empty path\n"); |
| 9435 | return CLI_TRUE; |
| 9436 | } |
| 9437 | } else if (strcmp(argv[i], "--dir") == 0) { |
| 9438 | if (i + 1 >= argc || !argv[i + 1] || !argv[i + 1][0] || argv[i + 1][0] == '-') { |
| 9439 | (void)fprintf(stderr, "error: --dir requires a non-empty path\n"); |
| 9440 | return CLI_TRUE; |
| 9441 | } |
| 9442 | requested_bin_dir = argv[++i]; |
| 9443 | } else if (strcmp(argv[i], "-y") != 0 && strcmp(argv[i], "--yes") != 0 && |
| 9444 | strcmp(argv[i], "-n") != 0 && strcmp(argv[i], "--no") != 0) { |
| 9445 | (void)fprintf(stderr, "error: unknown install option: %s\n", argv[i]); |
| 9446 | return CLI_TRUE; |
| 9447 | } |
| 9448 | } |
| 9449 | |
| 9450 | const char *home = cbm_get_home_dir(); |
| 9451 | if (!home) { |
| 9452 | (void)fprintf(stderr, "error: HOME not set (use USERPROFILE on Windows)\n"); |
| 9453 | return CLI_TRUE; |
| 9454 | } |
| 9455 | |
| 9456 | char bin_dir[CLI_BUF_1K]; |
| 9457 | int bin_dir_length = requested_bin_dir |
| 9458 | ? snprintf(bin_dir, sizeof(bin_dir), "%s", requested_bin_dir) |
| 9459 | : snprintf(bin_dir, sizeof(bin_dir), "%s/.local/bin", home); |
| 9460 | if (bin_dir_length <= 0 || (size_t)bin_dir_length >= sizeof(bin_dir)) { |
| 9461 | (void)fprintf(stderr, "error: install directory path is too long\n"); |
| 9462 | return CLI_TRUE; |
| 9463 | } |
| 9464 | cbm_normalize_path_sep(bin_dir); |
| 9465 | char bin_target[CLI_BUF_1K]; |
| 9466 | #ifdef _WIN32 |
| 9467 | int target_length = |
| 9468 | snprintf(bin_target, sizeof(bin_target), "%s/codebase-memory-mcp.exe", bin_dir); |
| 9469 | #else |
no test coverage detected