Skip to content

Commit d2c5b97

Browse files
committed
Remove ARRAY_OPTIONS_FALLBACK constant
Getters defensively normalize strings to arrays, so injectDotenv() doesn't need to know which options are arrays. No constants needed.
1 parent 5c94f10 commit d2c5b97

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/argv.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import {WriteStreams} from "./write-streams.js";
88
import chalkBase from "chalk";
99
import chalk from "chalk-template";
1010

11-
// Fallback for when _arrayKeys is not provided (e.g. tests calling handler() directly without yargs).
12-
// The CLI path derives array keys from yargs automatically.
13-
const ARRAY_OPTIONS_FALLBACK = new Set([
14-
"variable", "unsetVariable", "remoteVariables", "device",
15-
"network", "volume", "extraHost", "manual", "ignoreSchemaPaths",
16-
]);
17-
1811
export function splitSemicolonEnvVars (argv: Record<string, any>, arrayKeys: Set<string>, env: Record<string, string | undefined>): void {
1912
for (const [envKey, envValue] of Object.entries(env)) {
2013
if (!envKey.startsWith("GCL_") || envValue == null) continue;
@@ -117,10 +110,8 @@ export class Argv {
117110
currentVal.unshift(pair);
118111
}
119112
} else if (argv[argKey] == null) {
120-
const arrayKeys: Set<string> = argv._arrayKeys ?? ARRAY_OPTIONS_FALLBACK;
121-
if (arrayKeys.has(argKey)) {
122-
this.map.set(argKey, value.split(" "));
123-
} else if (value === "true") this.map.set(argKey, true);
113+
// Work around `dotenv.parse` limitation https://github.com/motdotla/dotenv/issues/51#issuecomment-552559070
114+
if (value === "true") this.map.set(argKey, true);
124115
else if (value === "false") this.map.set(argKey, false);
125116
else if (value === "null") this.map.set(argKey, null);
126117
else if (!isNaN(Number(value))) this.map.set(argKey, Number(value));
@@ -160,15 +151,18 @@ export class Argv {
160151
}
161152

162153
get volume (): string[] {
163-
return this.map.get("volume") ?? [];
154+
const val = this.map.get("volume") ?? [];
155+
return Array.isArray(val) ? val : val.split(" ");
164156
}
165157

166158
get network (): string[] {
167-
return this.map.get("network") ?? [];
159+
const val = this.map.get("network") ?? [];
160+
return Array.isArray(val) ? val : val.split(" ");
168161
}
169162

170163
get extraHost (): string[] {
171-
return this.map.get("extraHost") ?? [];
164+
const val = this.map.get("extraHost") ?? [];
165+
return Array.isArray(val) ? val : val.split(" ");
172166
}
173167

174168
get caFile (): string | null {
@@ -188,7 +182,8 @@ export class Argv {
188182
}
189183

190184
get remoteVariables (): string[] {
191-
return this.map.get("remoteVariables") ?? [];
185+
const val = this.map.get("remoteVariables") ?? [];
186+
return Array.isArray(val) ? val : val.split(" ");
192187
}
193188

194189
get variable (): {[key: string]: string} {
@@ -208,7 +203,8 @@ export class Argv {
208203
}
209204

210205
get manual (): string[] {
211-
return this.map.get("manual") ?? [];
206+
const val = this.map.get("manual") ?? [];
207+
return Array.isArray(val) ? val : val.split(" ");
212208
}
213209

214210
get job (): string[] {
@@ -241,7 +237,8 @@ export class Argv {
241237
}
242238

243239
get device (): string[] {
244-
return this.map.get("device") ?? [];
240+
const val = this.map.get("device") ?? [];
241+
return Array.isArray(val) ? val : val.split(" ");
245242
}
246243

247244
get ulimit (): string | null {

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ process.on("SIGUSR2", async () => await cleanupJobResources(jobs));
3535
try {
3636
const arrayKeys = new Set(yparser.getOptions().array.map((k: string) => camelCase(k)));
3737
splitSemicolonEnvVars(argv, arrayKeys, process.env);
38-
(argv as any)._arrayKeys = arrayKeys;
3938
await handler(argv, new WriteStreamsProcess(), jobs);
4039
const failedJobs = Executor.getFailed(jobs);
4140
process.exit(failedJobs.length > 0 ? 1 : 0);

0 commit comments

Comments
 (0)