Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

codexLaunchArgs.ts

39 lines1.3 KB

1import { tokenizeCliArgs } from "@t3tools/shared/cliArgs";
2​
3const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS";
4​
5export const resolveCodexLaunchArgs = (
6 launchArgs?: string,
7 environment: NodeJS.ProcessEnv = process.env,
8) => environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";
9​
10const codexLaunchArgv = (launchArgs?: string): ReadonlyArray<string> => tokenizeCliArgs(launchArgs);
11​
12export const codexAppServerArgs = (launchArgs?: string) => [
13 "app-server",
14 ...codexLaunchArgv(launchArgs),
15];
16​
17export const codexExecLaunchArgs = (launchArgs?: string) => {
18 const args = codexLaunchArgv(launchArgs);
19 const execArgs: Array<string> = [];
20​
21 for (let index = 0; index < args.length; index++) {
22 const arg = args[index];
23 if (arg === undefined) continue;
24​
25 if (arg === "--strict-config" || arg.startsWith("--config=") || arg.startsWith("-c=")) {
26 execArgs.push(arg);
27 } else if (arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable") {
28 const value = args[index + 1];
29 if (value !== undefined && !value.startsWith("-")) {
30 execArgs.push(arg, value);
31 index++;
32 }
33 } else if (arg.startsWith("--enable=") || arg.startsWith("--disable=")) {
34 execArgs.push(arg);
35 }
36 }
37​
38 return execArgs;
39};