mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(scripts): validate iOS node CLI values before help
This commit is contained in:
@@ -40,6 +40,10 @@ const hasFlag = (flag: string) => argv.includes(flag);
|
||||
const BOOLEAN_FLAGS = new Set(["--dangerous", "--help", "-h", "--json"]);
|
||||
const VALUE_FLAGS = new Set(["--node", "--token", "--url", "--wait-seconds"]);
|
||||
|
||||
function isMissingOptionValue(value: string | undefined): boolean {
|
||||
return !value || BOOLEAN_FLAGS.has(value) || VALUE_FLAGS.has(value) || value.startsWith("--");
|
||||
}
|
||||
|
||||
function failCli(message: string): never {
|
||||
writeStderrLine(message);
|
||||
process.exit(1);
|
||||
@@ -53,7 +57,7 @@ function validateArgs(): void {
|
||||
}
|
||||
if (VALUE_FLAGS.has(arg)) {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
if (isMissingOptionValue(value)) {
|
||||
failCli(`${arg} requires a value`);
|
||||
}
|
||||
index += 1;
|
||||
@@ -63,11 +67,11 @@ function validateArgs(): void {
|
||||
}
|
||||
}
|
||||
|
||||
validateArgs();
|
||||
if (hasFlag("--help") || hasFlag("-h")) {
|
||||
writeStdoutLine(usage());
|
||||
process.exit(0);
|
||||
}
|
||||
validateArgs();
|
||||
|
||||
type NodeListPayload = {
|
||||
ts?: number;
|
||||
|
||||
@@ -256,6 +256,14 @@ describe("ios-node-e2e", () => {
|
||||
expect(result.stdout).toBe("");
|
||||
});
|
||||
|
||||
it("rejects short flags as CLI option values before help handling", async () => {
|
||||
const result = await runScriptRaw(["--url", "-h", "--token", "token"]);
|
||||
|
||||
expect(result).toMatchObject({ signal: null, status: 1, timedOut: false });
|
||||
expect(result.stderr.trim()).toBe("--url requires a value");
|
||||
expect(result.stdout).toBe("");
|
||||
});
|
||||
|
||||
it("rejects malformed wait seconds before connecting", async () => {
|
||||
const result = await runScript("ws://127.0.0.1:9", ["--wait-seconds", "1e3"]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user