Skip to content

Commit 31a4765

Browse files
fix: Allow multi-line variable values via command line (#1315)
* fix: Allow multi-line variable values via command line * style: Add trailing comma to comply with linting rules
1 parent 398874d commit 31a4765

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/argv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class Argv {
122122
const variables: {[key: string]: string} = {};
123123
const pairs = typeof val == "string" ? val.split(" ") : val;
124124
(pairs ?? []).forEach((variablePair: string) => {
125-
const exec = /(?<key>\w*?)(=)(?<value>.*)/.exec(variablePair);
125+
const exec = /(?<key>\w*?)(=)(?<value>(.|\n|\r)*)/.exec(variablePair);
126126
if (exec?.groups?.key) {
127127
variables[exec.groups.key] = exec?.groups?.value;
128128
}

tests/test-cases/cli-option-variables/.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ test-job:
33
script:
44
- echo ${CLI_VAR}
55
- echo ${CLI_VAR_DOT}
6+
- echo "${CLI_MULTILINE}"

tests/test-cases/cli-option-variables/integration.cli-option-variables.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ test("cli-option-variables <test-job> --variable \"CLI_VAR=hello world\"", async
1313
await handler({
1414
cwd: "tests/test-cases/cli-option-variables",
1515
job: ["test-job"],
16-
variable: ["CLI_VAR=hello world", "CLI_VAR_DOT=dotdot"],
16+
variable: ["CLI_VAR=hello world", "CLI_VAR_DOT=dotdot", `CLI_MULTILINE=This is a multi
17+
line string`],
1718
}, writeStreams);
1819

1920
const expected = [
2021
chalk`{blueBright test-job} {greenBright >} hello world`,
2122
chalk`{blueBright test-job} {greenBright >} dotdot`,
23+
chalk`{blueBright test-job} {greenBright >} This is a multi`,
24+
chalk`{blueBright test-job} {greenBright >} line string`,
2225
];
2326
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
2427
});

0 commit comments

Comments
 (0)