Skip to content

Commit f6a99f2

Browse files
committed
Support key-value option lines
1 parent a1b46c2 commit f6a99f2

2 files changed

Lines changed: 52 additions & 7 deletions

File tree

dist/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36632,6 +36632,23 @@ var { VERSION, YAML, argv, dotenv, echo, expBackoff, fetch, fs, glob, globby, mi
3663236632
//#endregion
3663336633
//#region src/index.ts
3663436634
$.verbose = true;
36635+
function parseOptions(input) {
36636+
if (input.trim() === "") return {};
36637+
try {
36638+
return JSON.parse(input);
36639+
} catch {
36640+
const options = {};
36641+
for (const line of input.split("\n")) {
36642+
const trimmed = line.trim();
36643+
if (trimmed === "" || trimmed.startsWith("#")) continue;
36644+
const match = trimmed.match(/^([^:#]+):\s*(.*)$/);
36645+
if (match === null) throw new Error("Invalid options format");
36646+
const [, key, value] = match;
36647+
options[key.trim()] = value.trim().replace(/^["']|["']$/g, "");
36648+
}
36649+
return options;
36650+
}
36651+
}
3663536652
(async function main() {
3663636653
try {
3663736654
await ssh();
@@ -36718,9 +36735,10 @@ async function dep() {
3671836735
const options = [];
3671936736
try {
3672036737
const optionsArg = getInput("options");
36721-
if (optionsArg !== "") for (const [key, value] of Object.entries(JSON.parse(optionsArg))) options.push("-o", `${key}=${value}`);
36738+
for (const [key, value] of Object.entries(parseOptions(optionsArg))) options.push("-o", `${key}=${value}`);
3672236739
} catch (e) {
36723-
console.error("Invalid JSON in options");
36740+
setFailed("Invalid options format. Use JSON or key: value lines.");
36741+
return;
3672436742
}
3672536743
let phpBin = "php";
3672636744
const phpBinArg = getInput("php-binary");

src/index.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ interface DeployerManifestEntry {
1313
url: string
1414
}
1515

16+
function parseOptions(input: string): Record<string, string> {
17+
if (input.trim() === '') {
18+
return {}
19+
}
20+
21+
try {
22+
return JSON.parse(input) as Record<string, string>
23+
} catch {
24+
const options: Record<string, string> = {}
25+
for (const line of input.split('\n')) {
26+
const trimmed = line.trim()
27+
if (trimmed === '' || trimmed.startsWith('#')) {
28+
continue
29+
}
30+
31+
const match = trimmed.match(/^([^:#]+):\s*(.*)$/)
32+
if (match === null) {
33+
throw new Error('Invalid options format')
34+
}
35+
36+
const [, key, value] = match
37+
options[key.trim()] = value.trim().replace(/^["']|["']$/g, '')
38+
}
39+
40+
return options
41+
}
42+
}
43+
1644
void (async function main(): Promise<void> {
1745
try {
1846
await ssh()
@@ -146,13 +174,12 @@ async function dep(): Promise<void> {
146174
const options: string[] = []
147175
try {
148176
const optionsArg = core.getInput('options')
149-
if (optionsArg !== '') {
150-
for (const [key, value] of Object.entries(JSON.parse(optionsArg))) {
151-
options.push('-o', `${key}=${value}`)
152-
}
177+
for (const [key, value] of Object.entries(parseOptions(optionsArg))) {
178+
options.push('-o', `${key}=${value}`)
153179
}
154180
} catch (e) {
155-
console.error('Invalid JSON in options')
181+
core.setFailed('Invalid options format. Use JSON or key: value lines.')
182+
return
156183
}
157184

158185
let phpBin = 'php'

0 commit comments

Comments
 (0)