fix(scripts): validate iOS node CLI values before help · openclaw/openclaw@6b45e9a
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,10 @@ const hasFlag = (flag: string) => argv.includes(flag);
|
40 | 40 | const BOOLEAN_FLAGS = new Set(["--dangerous", "--help", "-h", "--json"]); |
41 | 41 | const VALUE_FLAGS = new Set(["--node", "--token", "--url", "--wait-seconds"]); |
42 | 42 | |
| 43 | +function isMissingOptionValue(value: string | undefined): boolean { |
| 44 | +return !value || BOOLEAN_FLAGS.has(value) || VALUE_FLAGS.has(value) || value.startsWith("--"); |
| 45 | +} |
| 46 | + |
43 | 47 | function failCli(message: string): never { |
44 | 48 | writeStderrLine(message); |
45 | 49 | process.exit(1); |
@@ -53,7 +57,7 @@ function validateArgs(): void {
|
53 | 57 | } |
54 | 58 | if (VALUE_FLAGS.has(arg)) { |
55 | 59 | const value = argv[index + 1]; |
56 | | -if (!value || value.startsWith("--")) { |
| 60 | +if (isMissingOptionValue(value)) { |
57 | 61 | failCli(`${arg} requires a value`); |
58 | 62 | } |
59 | 63 | index += 1; |
@@ -63,11 +67,11 @@ function validateArgs(): void {
|
63 | 67 | } |
64 | 68 | } |
65 | 69 | |
| 70 | +validateArgs(); |
66 | 71 | if (hasFlag("--help") || hasFlag("-h")) { |
67 | 72 | writeStdoutLine(usage()); |
68 | 73 | process.exit(0); |
69 | 74 | } |
70 | | -validateArgs(); |
71 | 75 | |
72 | 76 | type NodeListPayload = { |
73 | 77 | ts?: number; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -256,6 +256,14 @@ describe("ios-node-e2e", () => {
|
256 | 256 | expect(result.stdout).toBe(""); |
257 | 257 | }); |
258 | 258 | |
| 259 | +it("rejects short flags as CLI option values before help handling", async () => { |
| 260 | +const result = await runScriptRaw(["--url", "-h", "--token", "token"]); |
| 261 | + |
| 262 | +expect(result).toMatchObject({ signal: null, status: 1, timedOut: false }); |
| 263 | +expect(result.stderr.trim()).toBe("--url requires a value"); |
| 264 | +expect(result.stdout).toBe(""); |
| 265 | +}); |
| 266 | + |
259 | 267 | it("rejects malformed wait seconds before connecting", async () => { |
260 | 268 | const result = await runScript("ws://127.0.0.1:9", ["--wait-seconds", "1e3"]); |
261 | 269 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。