fix(scripts): reject short flag values in helper CLIs · openclaw/openclaw@beebb35
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ import {
|
13 | 13 | |
14 | 14 | function readPackageArgValue(argv, index) { |
15 | 15 | const value = argv[index + 1]; |
16 | | -if (value === undefined || value === "" || value.startsWith("--")) { |
| 16 | +if (value === undefined || value === "" || value.startsWith("-")) { |
17 | 17 | throw new Error("missing value for --package"); |
18 | 18 | } |
19 | 19 | return value; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -223,7 +223,7 @@ function parseArgs(argv: string[]): ScriptOptions {
|
223 | 223 | |
224 | 224 | if (arg === "--limit") { |
225 | 225 | const next = argv[index + 1]; |
226 | | -if (!next || next.startsWith("--") || !/^\d+$/u.test(next)) { |
| 226 | +if (!next || next.startsWith("-") || !/^\d+$/u.test(next)) { |
227 | 227 | throw new Error("Missing/invalid --limit value"); |
228 | 228 | } |
229 | 229 | const parsed = Number(next); |
@@ -237,7 +237,7 @@ function parseArgs(argv: string[]): ScriptOptions {
|
237 | 237 | |
238 | 238 | if (arg === "--model") { |
239 | 239 | const next = argv[index + 1]; |
240 | | -if (!next || next.startsWith("--")) { |
| 240 | +if (!next || next.startsWith("-")) { |
241 | 241 | throw new Error("Missing --model value"); |
242 | 242 | } |
243 | 243 | model = next; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -307,7 +307,7 @@ function readPackageDirArg(argv) {
|
307 | 307 | if (packageDir === "--help" || packageDir === "-h") { |
308 | 308 | return { help: true, packageDir: "" }; |
309 | 309 | } |
310 | | -if (!packageDir || packageDir.startsWith("--")) { |
| 310 | +if (!packageDir || packageDir.startsWith("-")) { |
311 | 311 | throw new Error(usage()); |
312 | 312 | } |
313 | 313 | const extraArg = args[1]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
5 | 5 | import { normalizeUpgradeSurvivorBaselineSpec } from "./lib/docker-e2e-plan.mjs"; |
6 | 6 | import { compareReleaseVersions, parseReleaseVersion } from "./lib/npm-publish-plan.mjs"; |
7 | 7 | |
8 | | -function parseArgs(argv) { |
| 8 | +export function parseArgs(argv) { |
9 | 9 | const args = new Map(); |
10 | 10 | for (let index = 0; index < argv.length; index += 1) { |
11 | 11 | const arg = argv[index]; |
@@ -14,7 +14,7 @@ function parseArgs(argv) {
|
14 | 14 | } |
15 | 15 | const key = arg.slice(2); |
16 | 16 | const value = argv[index + 1]; |
17 | | -if (value === undefined || value.startsWith("--")) { |
| 17 | +if (value === undefined || value.startsWith("-")) { |
18 | 18 | throw new Error(`missing value for --${key}`); |
19 | 19 | } |
20 | 20 | args.set(key, value); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -24,9 +24,11 @@ describe("label-open-issues helpers", () => {
|
24 | 24 | }); |
25 | 25 | |
26 | 26 | expect(() => testing.parseArgs(["--model", "--dry-run"])).toThrow("Missing --model value"); |
| 27 | +expect(() => testing.parseArgs(["--model", "-h"])).toThrow("Missing --model value"); |
27 | 28 | expect(() => testing.parseArgs(["--limit", "--dry-run"])).toThrow( |
28 | 29 | "Missing/invalid --limit value", |
29 | 30 | ); |
| 31 | +expect(() => testing.parseArgs(["--limit", "-h"])).toThrow("Missing/invalid --limit value"); |
30 | 32 | expect(() => testing.parseArgs(["--wat"])).toThrow("Unknown argument: --wat"); |
31 | 33 | }); |
32 | 34 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,7 @@ describe("plugin npm runtime build args", () => {
|
39 | 39 | expect(() => parseBulkBuildArgs(["--package", "--package", "extensions/slack"])).toThrow( |
40 | 40 | "missing value for --package", |
41 | 41 | ); |
| 42 | +expect(() => parseBulkBuildArgs(["--package", "-h"])).toThrow("missing value for --package"); |
42 | 43 | expect(() => parseSingleBuildArgs(["--package"])).toThrow( |
43 | 44 | "usage: node scripts/lib/plugin-npm-runtime-build.mjs <package-dir>", |
44 | 45 | ); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
3 | 3 | import { tmpdir } from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import { describe, expect, it } from "vitest"; |
6 | | -import { resolveBaselines } from "../../scripts/resolve-upgrade-survivor-baselines.mjs"; |
| 6 | +import { parseArgs, resolveBaselines } from "../../scripts/resolve-upgrade-survivor-baselines.mjs"; |
7 | 7 | |
8 | 8 | function withReleaseFixture<T>(releases: unknown[], fn: (file: string) => T): T { |
9 | 9 | const dir = mkdtempSync(path.join(tmpdir(), "openclaw-upgrade-baselines-")); |
@@ -28,6 +28,11 @@ function withJsonFixture<T>(name: string, contents: unknown, fn: (file: string)
|
28 | 28 | } |
29 | 29 | |
30 | 30 | describe("scripts/resolve-upgrade-survivor-baselines", () => { |
| 31 | +it("rejects short flag values before resolving baselines", () => { |
| 32 | +expect(() => parseArgs(["--fallback", "-h"])).toThrow("missing value for --fallback"); |
| 33 | +expect(() => parseArgs(["--github-output", "-h"])).toThrow("missing value for --github-output"); |
| 34 | +}); |
| 35 | + |
31 | 36 | it("keeps the single fallback baseline when no expanded request is provided", () => { |
32 | 37 | expect(resolveBaselines(new Map([["fallback", "2026.4.23"]]))).toEqual(["openclaw@2026.4.23"]); |
33 | 38 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。