mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-25 06:49:31 +00:00
fix(scripts): reject short flag values in release docs parsers
This commit is contained in:
@@ -83,7 +83,7 @@ function parseArgs(argv) {
|
||||
|
||||
function readOptionValue(argv, index, option) {
|
||||
const value = argv[index + 1] ?? "";
|
||||
if (!value || value.startsWith("--")) {
|
||||
if (!value || value.startsWith("-")) {
|
||||
throw new Error(`Missing value for ${option}.`);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -94,7 +94,7 @@ function parsePositiveIntegerArg(raw, label) {
|
||||
|
||||
function readRequiredValue(argv, index, label) {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
if (!value || value.startsWith("-")) {
|
||||
throw new Error(`${label} requires a value`);
|
||||
}
|
||||
return value;
|
||||
@@ -116,7 +116,10 @@ export function parseArgs(argv) {
|
||||
continue;
|
||||
}
|
||||
if (part === "--max-errors") {
|
||||
maxErrors = parsePositiveIntegerArg(argv[index + 1], "--max-errors");
|
||||
maxErrors = parsePositiveIntegerArg(
|
||||
readRequiredValue(argv, index, "--max-errors"),
|
||||
"--max-errors",
|
||||
);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ function parseArgs(argv) {
|
||||
|
||||
function readOptionValue(argv, index, option) {
|
||||
const value = argv[index + 1] ?? "";
|
||||
if (!value || value.startsWith("--")) {
|
||||
if (!value || value.startsWith("-")) {
|
||||
throw new Error(`Missing value for ${option}.`);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -30,12 +30,19 @@ function runNode(args: string[], env: NodeJS.ProcessEnv = {}) {
|
||||
const e = error as { stdout?: unknown; stderr?: unknown };
|
||||
return {
|
||||
ok: false,
|
||||
stdout: Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : String(e.stdout ?? ""),
|
||||
stderr: Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : String(e.stderr ?? ""),
|
||||
stdout: formatProcessOutput(e.stdout),
|
||||
stderr: formatProcessOutput(e.stderr),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function formatProcessOutput(value: unknown): string {
|
||||
if (Buffer.isBuffer(value)) {
|
||||
return value.toString("utf8");
|
||||
}
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function runGit(args: string[], cwd?: string, env: NodeJS.ProcessEnv = {}) {
|
||||
execFileSync("git", args, {
|
||||
cwd,
|
||||
@@ -127,11 +134,17 @@ describe("scripts/android-release-signing.mjs", () => {
|
||||
it.each([
|
||||
["--mode"],
|
||||
["--mode", "--manifest"],
|
||||
["--mode", "-h"],
|
||||
["--manifest"],
|
||||
["--manifest", "-h"],
|
||||
["--workspace", "--mode"],
|
||||
["--workspace", "-h"],
|
||||
["--materialized-dir", "--mode"],
|
||||
["--materialized-dir", "-h"],
|
||||
["--keystore", "--mode"],
|
||||
["--keystore", "-h"],
|
||||
["--properties", "--mode"],
|
||||
["--properties", "-h"],
|
||||
])("rejects missing values for %s before release signing work", (...args) => {
|
||||
const result = runNode(args);
|
||||
|
||||
|
||||
@@ -20,11 +20,13 @@ describe("scripts/check-docs-mdx", () => {
|
||||
expect(() => parseArgs(["--max-errors", "0"])).toThrow(
|
||||
"--max-errors must be a positive integer",
|
||||
);
|
||||
expect(() => parseArgs(["--max-errors"])).toThrow("--max-errors must be a positive integer");
|
||||
expect(() => parseArgs(["--max-errors"])).toThrow("--max-errors requires a value");
|
||||
expect(() => parseArgs(["--max-errors", "-h"])).toThrow("--max-errors requires a value");
|
||||
});
|
||||
|
||||
it("rejects missing JSON report output paths", () => {
|
||||
expect(() => parseArgs(["--json-out"])).toThrow("--json-out requires a value");
|
||||
expect(() => parseArgs(["--json-out", "-h"])).toThrow("--json-out requires a value");
|
||||
expect(() => parseArgs(["--json-out", "--max-errors", "3"])).toThrow(
|
||||
"--json-out requires a value",
|
||||
);
|
||||
|
||||
@@ -16,12 +16,19 @@ function runSigningResult(args: string[]): { ok: boolean; stdout: string; stderr
|
||||
const e = error as { stdout?: unknown; stderr?: unknown };
|
||||
return {
|
||||
ok: false,
|
||||
stdout: Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : String(e.stdout ?? ""),
|
||||
stderr: Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : String(e.stderr ?? ""),
|
||||
stdout: formatProcessOutput(e.stdout),
|
||||
stderr: formatProcessOutput(e.stderr),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function formatProcessOutput(value: unknown): string {
|
||||
if (Buffer.isBuffer(value)) {
|
||||
return value.toString("utf8");
|
||||
}
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function runSigning(mode: string): string {
|
||||
return execFileSync(process.execPath, [SCRIPT, "--mode", mode], {
|
||||
encoding: "utf8",
|
||||
@@ -33,7 +40,9 @@ describe("scripts/ios-release-signing.mjs", () => {
|
||||
it.each([
|
||||
["--mode"],
|
||||
["--mode", "--manifest"],
|
||||
["--mode", "-h"],
|
||||
["--manifest"],
|
||||
["--manifest", "-h"],
|
||||
])("rejects missing values for %s before reading signing manifests", (...args) => {
|
||||
const result = runSigningResult(args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user