| 28 | } |
| 29 | |
| 30 | export class Command implements TCommand<ChildProcess<string>> { |
| 31 | private sidecarCommand: ShellCommand<string> |
| 32 | private childProcess?: Child |
| 33 | private args: string[] |
| 34 | private cancelled = false |
| 35 | |
| 36 | public static ADDITIONAL_ENV_VARS: string = "" |
| 37 | public static HTTP_PROXY: string = "" |
| 38 | public static HTTPS_PROXY: string = "" |
| 39 | public static NO_PROXY: string = "" |
| 40 | |
| 41 | constructor(args: string[]) { |
| 42 | debug("commands", "Creating Devpod command with args: ", args) |
| 43 | const extraEnvVars = Command.ADDITIONAL_ENV_VARS.split(",") |
| 44 | .map((envVarStr) => envVarStr.split("=")) |
| 45 | .reduce( |
| 46 | (acc, pair) => { |
| 47 | const [key, value] = pair |
| 48 | if (key === undefined || value === undefined) { |
| 49 | return acc |
| 50 | } |
| 51 | |
| 52 | return { ...acc, [key]: value } |
| 53 | }, |
| 54 | {} as Record<string, string> |
| 55 | ) |
| 56 | |
| 57 | // set proxy related environment variables |
| 58 | if (Command.HTTP_PROXY) { |
| 59 | extraEnvVars["HTTP_PROXY"] = Command.HTTP_PROXY |
| 60 | } |
| 61 | if (Command.HTTPS_PROXY) { |
| 62 | extraEnvVars["HTTPS_PROXY"] = Command.HTTPS_PROXY |
| 63 | } |
| 64 | if (Command.NO_PROXY) { |
| 65 | extraEnvVars["NO_PROXY"] = Command.NO_PROXY |
| 66 | } |
| 67 | |
| 68 | // allows the CLI to detect if commands have been invoked from the UI |
| 69 | extraEnvVars[DEVPOD_UI_ENV_VAR] = "true" |
| 70 | |
| 71 | if (import.meta.env.TAURI_IS_FLATPAK === "true") { |
| 72 | this.sidecarCommand = ShellCommand.create("run-path-devpod-wrapper", args, { |
| 73 | env: { ...extraEnvVars, ["FLATPAK_ID"]: "sh.loft.devpod" }, |
| 74 | }) |
| 75 | } else { |
| 76 | this.sidecarCommand = ShellCommand.sidecar(DEVPOD_BINARY, args, { env: extraEnvVars }) |
| 77 | } |
| 78 | this.args = args |
| 79 | } |
| 80 | |
| 81 | public async run(): Promise<Result<ChildProcess<string>>> { |
| 82 | try { |
| 83 | const rawResult = await this.sidecarCommand.execute() |
| 84 | debug("commands", `Result for command with args ${this.args}:`, rawResult) |
| 85 | |
| 86 | return Return.Value(rawResult) |
| 87 | } catch (e) { |
nothing calls this directly
no outgoing calls
no test coverage detected