mirror of
https://github.com/threeal/cmake-action.git
synced 2026-02-01 19:40:49 +00:00
feat: parse multi values inputs with quotation (#520)
* feat: parse quotation in `options` input Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * feat: parse quotation in `args` input Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * feat: parse quotation in `build-args` input Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
This commit is contained in:
@@ -99,24 +99,29 @@ describe("get action context", () => {
|
||||
{
|
||||
name: "with additional options specified",
|
||||
inputs: {
|
||||
options: "BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON",
|
||||
options: `BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON FOO="BAR BAZ"`,
|
||||
},
|
||||
expectedContext: {
|
||||
configure: {
|
||||
generator: "",
|
||||
options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
||||
options: [
|
||||
"BUILD_TESTING=ON",
|
||||
"BUILD_EXAMPLES=ON",
|
||||
"BUILD_DOCS=ON",
|
||||
"FOO=BAR BAZ",
|
||||
],
|
||||
args: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with additional arguments specified",
|
||||
inputs: { args: "-Wdev -Wdeprecated\n--fresh" },
|
||||
inputs: { args: `-Wdev -Wdeprecated\n--fresh --foo "bar baz"` },
|
||||
expectedContext: {
|
||||
configure: {
|
||||
generator: "",
|
||||
options: [],
|
||||
args: ["-Wdev", "-Wdeprecated", "--fresh"],
|
||||
args: ["-Wdev", "-Wdeprecated", "--fresh", "--foo", "bar baz"],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -127,11 +132,11 @@ describe("get action context", () => {
|
||||
},
|
||||
{
|
||||
name: "with additional build arguments specified",
|
||||
inputs: { "build-args": "--target foo\n--parallel 8" },
|
||||
inputs: { "build-args": `--target foo\n--parallel 8 --foo "bar baz"` },
|
||||
expectedContext: {
|
||||
build: {
|
||||
enabled: false,
|
||||
args: ["--target", "foo", "--parallel", "8"],
|
||||
args: ["--target", "foo", "--parallel", "8", "--foo", "bar baz"],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -145,10 +150,10 @@ describe("get action context", () => {
|
||||
"cxx-compiler": "clang++",
|
||||
"c-flags": "-Werror -Wall\n-Wextra",
|
||||
"cxx-flags": "-Werror -Wall\n-Wextra -Wpedantic",
|
||||
options: "BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON",
|
||||
args: "-Wdev -Wdeprecated\n--fresh",
|
||||
options: `BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON FOO="BAR BAZ"`,
|
||||
args: `-Wdev -Wdeprecated\n--fresh --foo "bar baz"`,
|
||||
"run-build": "true",
|
||||
"build-args": "--target foo\n--parallel 8",
|
||||
"build-args": `--target foo\n--parallel 8 --foo "bar baz"`,
|
||||
},
|
||||
expectedContext: {
|
||||
sourceDir: "project",
|
||||
@@ -163,12 +168,13 @@ describe("get action context", () => {
|
||||
"BUILD_TESTING=ON",
|
||||
"BUILD_EXAMPLES=ON",
|
||||
"BUILD_DOCS=ON",
|
||||
"FOO=BAR BAZ",
|
||||
],
|
||||
args: ["-Wdev", "-Wdeprecated", "--fresh"],
|
||||
args: ["-Wdev", "-Wdeprecated", "--fresh", "--foo", "bar baz"],
|
||||
},
|
||||
build: {
|
||||
enabled: true,
|
||||
args: ["--target", "foo", "--parallel", "8"],
|
||||
args: ["--target", "foo", "--parallel", "8", "--foo", "bar baz"],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getInput } from "gha-utils";
|
||||
import path from "node:path";
|
||||
import { parse } from "shell-quote";
|
||||
|
||||
export interface Context {
|
||||
sourceDir: string;
|
||||
@@ -39,10 +40,7 @@ export function getContext(): Context {
|
||||
|
||||
input = getInput("options");
|
||||
if (input) {
|
||||
const opts = input.split(/\s+/).filter((arg) => arg != "");
|
||||
for (const opt of opts) {
|
||||
options.push(opt);
|
||||
}
|
||||
options.push(...parse(input).map((opt) => opt.toString()));
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -51,15 +49,11 @@ export function getContext(): Context {
|
||||
configure: {
|
||||
generator: getInput("generator"),
|
||||
options,
|
||||
args: getInput("args")
|
||||
.split(/\s+/)
|
||||
.filter((arg) => arg != ""),
|
||||
args: parse(getInput("args")).map((arg) => arg.toString()),
|
||||
},
|
||||
build: {
|
||||
enabled: getInput("run-build") == "true",
|
||||
args: getInput("build-args")
|
||||
.split(/\s+/)
|
||||
.filter((arg) => arg != ""),
|
||||
args: parse(getInput("build-args")).map((arg) => arg.toString()),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user