| 863 | } |
| 864 | |
| 865 | static int run_cli(int argc, char **argv, cbm_project_lock_manager_t *project_locks, |
| 866 | main_local_maintenance_context_t *maintenance_context) { |
| 867 | cbm_cli_output_flags_t output_flags; |
| 868 | char output_error[CBM_SZ_512] = {0}; |
| 869 | if (!cbm_cli_output_flags_parse(&argc, argv, &output_flags, output_error, |
| 870 | sizeof(output_error))) { |
| 871 | (void)fprintf(stderr, "error: %s\n", |
| 872 | output_error[0] ? output_error : "invalid output mode"); |
| 873 | (void)fprintf(stderr, CLI_USAGE); |
| 874 | return SKIP_ONE; |
| 875 | } |
| 876 | cbm_cli_diagnostics_configure(output_flags.quiet_requested, output_flags.verbose_requested); |
| 877 | if (argc == 1 && argv && (strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0)) { |
| 878 | (void)fputs(CLI_USAGE, stdout); |
| 879 | return 0; |
| 880 | } |
| 881 | if (argc < MAIN_MIN_ARGC) { |
| 882 | (void)fprintf(stderr, CLI_USAGE); |
| 883 | return SKIP_ONE; |
| 884 | } |
| 885 | |
| 886 | bool raw_json = cli_strip_flag(&argc, argv, "--json"); |
| 887 | |
| 888 | /* Supervisor worker role: when this process was spawned as a supervised index |
| 889 | * worker, run indexing in-process (never re-supervise) and write the result to |
| 890 | * the given file for the parent to read back. Stripped here so the tool |
| 891 | * dispatch below sees only the tool name + its args. */ |
| 892 | bool index_worker = cli_strip_flag(&argc, argv, "--index-worker"); |
| 893 | (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_BUILD_ARG); |
| 894 | const char *response_out = cli_strip_flag_value(&argc, argv, "--response-out"); |
| 895 | (void)cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MEMORY_BUDGET_ARG); |
| 896 | bool worker_single_thread = cli_strip_flag(&argc, argv, CBM_INDEX_WORKER_SINGLE_THREAD_ARG); |
| 897 | const char *worker_marker = cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_MARKER_ARG); |
| 898 | const char *worker_quarantine = |
| 899 | cli_strip_flag_value(&argc, argv, CBM_INDEX_WORKER_QUARANTINE_ARG); |
| 900 | if (index_worker) { |
| 901 | /* The graph lives on this process's heaps: SQLite gets heaps of its |
| 902 | * own here, and only here (cbm_sqlite_dedicated_heap). */ |
| 903 | cbm_sqlite_dedicated_heap(true); |
| 904 | cbm_memev_process_role("worker"); |
| 905 | } |
| 906 | cbm_index_set_worker_role_options(index_worker, response_out, worker_single_thread, |
| 907 | worker_marker, worker_quarantine, |
| 908 | cbm_index_worker_memory_budget_bytes()); |
| 909 | |
| 910 | if (argc < MAIN_MIN_ARGC) { |
| 911 | (void)fprintf(stderr, CLI_USAGE); |
| 912 | return SKIP_ONE; |
| 913 | } |
| 914 | |
| 915 | const char *tool_name = argv[0]; |
| 916 | int rem_argc = argc - SKIP_ONE; /* args following the tool name */ |
| 917 | char **rem_argv = argv + SKIP_ONE; |
| 918 | |
| 919 | /* --help / -h : print per-tool help (from the tool's input_schema) and exit |
| 920 | * before any server work. */ |
| 921 | for (int i = 0; i < rem_argc; i++) { |
| 922 | if (strcmp(rem_argv[i], "--help") == 0 || strcmp(rem_argv[i], "-h") == 0) { |
no test coverage detected