mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-08 08:04:25 +00:00
Rework input parsing to try-catch JSON
This commit is contained in:
+9
-5
@@ -180,24 +180,28 @@ export async function resolve(inputs: string[]): Promise<Record<string, any>> {
|
||||
}
|
||||
|
||||
for (const input of inputs) {
|
||||
let jsonObj;
|
||||
let data: string;
|
||||
if (input.startsWith("@")) {
|
||||
let data: string;
|
||||
if (input == "@-") {
|
||||
data = new TextDecoder().decode(await readAll(Deno.stdin));
|
||||
} else {
|
||||
data = await Deno.readTextFile(input.substring(1));
|
||||
}
|
||||
jsonObj = JSON.parse(data);
|
||||
} else {
|
||||
if (input.startsWith("{")) {
|
||||
jsonObj = JSON.parse(input);
|
||||
data = input;
|
||||
} else {
|
||||
const key = input.split("=", 1)[0];
|
||||
const value = JSON.parse(input.substring(key.length + 1));
|
||||
jsonObj = Object.fromEntries([[key, value]]);
|
||||
data = JSON.stringify(Object.fromEntries([[key, value]]));
|
||||
}
|
||||
}
|
||||
let jsonObj;
|
||||
try {
|
||||
jsonObj = JSON.parse(data);
|
||||
} catch {
|
||||
jsonObj = data;
|
||||
}
|
||||
result = { ...result, ...jsonObj };
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user