| 820 | } |
| 821 | |
| 822 | static int run_cli(int argc, char **argv, cbm_project_lock_manager_t *project_locks, |
| 823 | main_local_maintenance_context_t *maintenance_context) { |
| 824 | cbm_cli_output_flags_t output_flags; |
| 825 | char output_error[CBM_SZ_512] = {0}; |
| 826 | if (!cbm_cli_output_flags_parse(&argc, argv, &output_flags, output_error, |
| 827 | sizeof(output_error))) { |
| 828 | (void)fprintf(stderr, "error: %s\n", |
| 829 | output_error[0] ? output_error : "invalid output mode"); |
| 830 | (void)fprintf(stderr, CLI_USAGE); |
| 831 | return SKIP_ONE; |
| 832 | } |
| 833 | cbm_cli_diagnostics_configure(output_flags.quiet_requested, output_flags.verbose_requested); |
| 834 | if (argc == 1 && argv && (strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0)) { |
| 835 | (void)fputs(CLI_USAGE, stdout); |
| 836 | return 0; |
| 837 | } |
| 838 | if (argc < MAIN_MIN_ARGC) { |
| 839 | (void)fprintf(stderr, CLI_USAGE); |
| 840 | return SKIP_ONE; |
| 841 | } |
| 842 | |
| 843 | bool raw_json = cli_strip_flag(&argc, argv, "--json"); |
| 844 | |
| 845 | /* Supervisor worker role: when this process was spawned as a supervised index |
| 846 | * worker, run indexing in-process (never re-supervise) and write the result to |
| 847 | * the given file for the parent to read back. Stripped here so the tool |
| 848 | * dispatch below sees only the tool name + its args. */ |
| 849 | bool index_worker = cli_strip_flag(&argc, argv, "--index-worker"); |
| 850 | (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_BUILD_ARG); |
| 851 | const char *response_out = cli_strip_flag_value(&argc, argv, "--response-out"); |
| 852 | (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MEMORY_BUDGET_ARG); |
| 853 | bool worker_single_thread = cli_strip_flag(&argc, argv, CBM_INDEX_WORKER_SINGLE_THREAD_ARG); |
| 854 | const char *worker_marker = cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MARKER_ARG); |
| 855 | const char *worker_quarantine = |
| 856 | cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_QUARANTINE_ARG); |
| 857 | if (index_worker) { |
| 858 | /* The graph lives on this process's heaps: SQLite gets heaps of its |
| 859 | * own here, and only here (cbm_sqlite_dedicated_heap). */ |
| 860 | cbm_sqlite_dedicated_heap(true); |
| 861 | } |
| 862 | cbm_index_set_worker_role_options(index_worker, response_out, worker_single_thread, |
| 863 | worker_marker, worker_quarantine, |
| 864 | cbm_index_worker_memory_budget_bytes()); |
| 865 | |
| 866 | if (argc < MAIN_MIN_ARGC) { |
| 867 | (void)fprintf(stderr, CLI_USAGE); |
| 868 | return SKIP_ONE; |
| 869 | } |
| 870 | |
| 871 | const char *tool_name = argv[0]; |
| 872 | int rem_argc = argc - SKIP_ONE; /* args following the tool name */ |
| 873 | char **rem_argv = argv + SKIP_ONE; |
| 874 | |
| 875 | /* --help / -h : print per-tool help (from the tool's input_schema) and exit |
| 876 | * before any server work. */ |
| 877 | for (int i = 0; i < rem_argc; i++) { |
| 878 | if (strcmp(rem_argv[i], "--help") == 0 || strcmp(rem_argv[i], "-h") == 0) { |
| 879 | if (cbm_cli_print_tool_help(tool_name) != 0) { |
no test coverage detected