Skip to content

Commit 12b807e

Browse files
committed
Fix verbosity parsing from options
1 parent a1b46c2 commit 12b807e

2 files changed

Lines changed: 70 additions & 16 deletions

File tree

dist/index.js

Lines changed: 28 additions & 6 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();
@@ -36712,16 +36729,21 @@ async function dep() {
3671236729
const recipeInput = getInput("recipe");
3671336730
if (recipeInput !== "") recipeArgs.push(`--file=${recipeInput}`);
3671436731
const ansi = getBooleanInput("ansi") ? "--ansi" : "--no-ansi";
36715-
const verbosityArgs = [];
36716-
const verbosityInput = getInput("verbosity");
36717-
if (verbosityInput !== "") verbosityArgs.push(verbosityInput);
3671836732
const options = [];
36733+
let verbosityInput = getInput("verbosity");
3671936734
try {
36720-
const optionsArg = getInput("options");
36721-
if (optionsArg !== "") for (const [key, value] of Object.entries(JSON.parse(optionsArg))) options.push("-o", `${key}=${value}`);
36735+
const parsedOptions = parseOptions(getInput("options"));
36736+
if (parsedOptions.verbosity !== void 0) {
36737+
verbosityInput = parsedOptions.verbosity;
36738+
delete parsedOptions.verbosity;
36739+
}
36740+
for (const [key, value] of Object.entries(parsedOptions)) options.push("-o", `${key}=${value}`);
3672236741
} catch (e) {
36723-
console.error("Invalid JSON in options");
36742+
setFailed("Invalid options format. Use JSON or key: value lines.");
36743+
return;
3672436744
}
36745+
const verbosityArgs = [];
36746+
if (verbosityInput !== "") verbosityArgs.push(verbosityInput);
3672536747
let phpBin = "php";
3672636748
const phpBinArg = getInput("php-binary");
3672736749
if (phpBinArg !== "") phpBin = phpBinArg;

src/index.ts

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

16+
type ParsedOptions = Record<string, string>
17+
18+
function parseOptions(input: string): ParsedOptions {
19+
if (input.trim() === '') {
20+
return {}
21+
}
22+
23+
try {
24+
return JSON.parse(input) as ParsedOptions
25+
} catch {
26+
const options: ParsedOptions = {}
27+
for (const line of input.split('\n')) {
28+
const trimmed = line.trim()
29+
if (trimmed === '' || trimmed.startsWith('#')) {
30+
continue
31+
}
32+
const match = trimmed.match(/^([^:#]+):\s*(.*)$/)
33+
if (match === null) {
34+
throw new Error('Invalid options format')
35+
}
36+
const [, key, value] = match
37+
options[key.trim()] = value.trim().replace(/^['"]|['"]$/g, '')
38+
}
39+
return options
40+
}
41+
}
42+
1643
void (async function main(): Promise<void> {
1744
try {
1845
await ssh()
@@ -138,21 +165,26 @@ async function dep(): Promise<void> {
138165
}
139166

140167
const ansi = core.getBooleanInput('ansi') ? '--ansi' : '--no-ansi'
141-
const verbosityArgs: string[] = []
142-
const verbosityInput = core.getInput('verbosity')
143-
if (verbosityInput !== '') {
144-
verbosityArgs.push(verbosityInput)
145-
}
146168
const options: string[] = []
169+
let verbosityInput = core.getInput('verbosity')
147170
try {
148171
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-
}
172+
const parsedOptions = parseOptions(optionsArg)
173+
if (parsedOptions.verbosity !== undefined) {
174+
verbosityInput = parsedOptions.verbosity
175+
delete parsedOptions.verbosity
176+
}
177+
for (const [key, value] of Object.entries(parsedOptions)) {
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
183+
}
184+
185+
const verbosityArgs: string[] = []
186+
if (verbosityInput !== '') {
187+
verbosityArgs.push(verbosityInput)
156188
}
157189

158190
let phpBin = 'php'

0 commit comments

Comments
 (0)