Skip to content

Commit efda97e

Browse files
committed
change to for and while loop with early return
1 parent fc0c1ce commit efda97e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

packages/cloudflare/src/cli/args.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,21 @@ export function getArgs(): Arguments {
8787
export function getPassthroughArgs<T extends ParseArgsConfig>(args: string[], { options = {} }: T) {
8888
const passthroughArgs: string[] = [];
8989

90-
args.forEach((fullArg, idx) => {
91-
const [, name] = /^--?(\w[\w-_]*)(=.+)?$/.exec(fullArg) ?? [];
92-
if (name && !(name in options)) {
93-
passthroughArgs.push(fullArg);
90+
for (let i = 0; i < args.length; i++) {
91+
if (args[i] === "--") {
92+
passthroughArgs.push(...args.slice(i + 1));
93+
return passthroughArgs;
94+
}
9495

95-
for (let i = idx + 1; i < args.length; i++) {
96-
const arg = args[i];
96+
const [, name] = /^--?(\w[\w-_]*)(=.+)?$/.exec(args[i]!) ?? [];
97+
if (name && !(name in options)) {
98+
passthroughArgs.push(args[i]!);
9799

98-
if (!arg || arg.startsWith("-")) {
99-
break;
100-
} else {
101-
passthroughArgs.push(arg);
102-
}
100+
while (!args[i + 1]?.startsWith("-")) {
101+
passthroughArgs.push(args[++i]!);
103102
}
104103
}
105-
});
104+
}
106105

107106
return passthroughArgs;
108107
}

0 commit comments

Comments
 (0)