Try to handle a subcommand (cli/install/uninstall/update/config/--version/--help). * Returns -1 if no subcommand matched, otherwise the exit code. */
| 531 | /* Try to handle a subcommand (cli/install/uninstall/update/config/--version/--help). |
| 532 | * Returns -1 if no subcommand matched, otherwise the exit code. */ |
| 533 | static int handle_subcommand(int argc, char **argv) { |
| 534 | /* First scan: global flags */ |
| 535 | for (int i = SKIP_ONE; i < argc; i++) { |
| 536 | if (strcmp(argv[i], "--profile") == 0) { |
| 537 | cbm_profile_enable(); |
| 538 | } |
| 539 | } |
| 540 | for (int i = SKIP_ONE; i < argc; i++) { |
| 541 | if (strcmp(argv[i], "--version") == 0) { |
| 542 | printf("codebase-memory-mcp %s\n", CBM_VERSION); |
| 543 | return 0; |
| 544 | } |
| 545 | if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { |
| 546 | print_help(); |
| 547 | return 0; |
| 548 | } |
| 549 | if (strcmp(argv[i], "cli") == 0) { |
| 550 | cbm_mem_init(cbm_mem_ram_fraction_for_total(cbm_system_info().total_ram)); |
| 551 | return run_cli(argc - i - SKIP_ONE, argv + i + SKIP_ONE); |
| 552 | } |
| 553 | if (strcmp(argv[i], "hook-augment") == 0) { |
| 554 | cbm_mem_init(cbm_mem_ram_fraction_for_total(cbm_system_info().total_ram)); |
| 555 | return cbm_cmd_hook_augment(); |
| 556 | } |
| 557 | if (strcmp(argv[i], "install") == 0) { |
| 558 | return cbm_cmd_install(argc - i - SKIP_ONE, argv + i + SKIP_ONE); |
| 559 | } |
| 560 | if (strcmp(argv[i], "uninstall") == 0) { |
| 561 | return cbm_cmd_uninstall(argc - i - SKIP_ONE, argv + i + SKIP_ONE); |
| 562 | } |
| 563 | if (strcmp(argv[i], "update") == 0) { |
| 564 | return cbm_cmd_update(argc - i - SKIP_ONE, argv + i + SKIP_ONE); |
| 565 | } |
| 566 | if (strcmp(argv[i], "config") == 0) { |
| 567 | return cbm_cmd_config(argc - i - SKIP_ONE, argv + i + SKIP_ONE); |
| 568 | } |
| 569 | } |
| 570 | return CBM_NOT_FOUND; |
| 571 | } |
| 572 | |
| 573 | /* Parse --ui= and --port= flags. Returns true if config was modified. */ |
| 574 | static bool parse_ui_flags(int argc, char **argv, cbm_ui_config_t *cfg, bool *explicit_enable) { |
no test coverage detected