more optional props

This commit is contained in:
SamKirkland
2020-08-30 00:05:41 -05:00
parent fc9de49cd2
commit 4fe6844638
3 changed files with 68 additions and 26 deletions

View File

@@ -9,14 +9,15 @@ async function runDeployment() {
password: core.getInput("password", { required: true }),
protocol: optionalProtocol("protocol", core.getInput("protocol")),
port: optionalInt("port", core.getInput("port")),
"local-dir": core.getInput("local-dir"),
"server-dir": core.getInput("server-dir"),
"state-name": core.getInput("state-name"),
"local-dir": optionalString(core.getInput("local-dir")),
"server-dir": optionalString(core.getInput("server-dir")),
"state-name": optionalString(core.getInput("state-name")),
"dry-run": optionalBoolean("dry-run", core.getInput("dry-run")),
"dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
"include": optionalStringArray("include", core.getInput("include")),
"exclude": optionalStringArray("exclude", core.getInput("exclude")),
"log-level": optionalLogLevel("log-level", core.getInput("log-level"))
"log-level": optionalLogLevel("log-level", core.getInput("log-level")),
"security": optionalSecurity("security", core.getInput("security"))
};
@@ -36,10 +37,16 @@ runDeployment();
function optionalString(rawValue: string): string | undefined {
if (rawValue.length === 0) {
return undefined;
}
return rawValue;
}
function optionalBoolean(argumentName: string, rawValue: string | undefined): boolean | undefined {
if (rawValue === undefined) {
function optionalBoolean(argumentName: string, rawValue: string): boolean | undefined {
if (rawValue.length === 0) {
return undefined;
}
@@ -54,8 +61,8 @@ function optionalBoolean(argumentName: string, rawValue: string | undefined): bo
core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
}
function optionalProtocol(argumentName: string, rawValue: string | undefined): "ftp" | "ftps" | "ftps-legacy" | undefined {
if (rawValue === undefined) {
function optionalProtocol(argumentName: string, rawValue: string): "ftp" | "ftps" | "ftps-legacy" | undefined {
if (rawValue.length === 0) {
return undefined;
}
@@ -73,8 +80,8 @@ function optionalProtocol(argumentName: string, rawValue: string | undefined): "
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
}
function optionalLogLevel(argumentName: string, rawValue: string | undefined): "warn" | "info" | "debug" | undefined {
if (rawValue === undefined) {
function optionalLogLevel(argumentName: string, rawValue: string): "warn" | "info" | "debug" | undefined {
if (rawValue.length === 0) {
return undefined;
}
@@ -92,13 +99,28 @@ function optionalLogLevel(argumentName: string, rawValue: string | undefined): "
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "warn", "info", or "debug" instead.`);
}
function optionalInt(argumentName: string, rawValue: string | undefined): number | undefined {
if (rawValue === undefined) {
function optionalSecurity(argumentName: string, rawValue: string): "loose" | "strict" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
const valueAsNumber = parseFloat(cleanValue);
if (cleanValue === "loose") {
return "loose";
}
if (cleanValue === "strict") {
return "strict";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
}
function optionalInt(argumentName: string, rawValue: string): number | undefined {
if (rawValue.length === 0) {
return undefined;
}
const valueAsNumber = parseFloat(rawValue);
if (Number.isInteger(valueAsNumber)) {
return valueAsNumber;
@@ -107,8 +129,8 @@ function optionalInt(argumentName: string, rawValue: string | undefined): number
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
}
function optionalStringArray(argumentName: string, rawValue: string | undefined): string[] | undefined {
if (rawValue === undefined) {
function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined {
if (rawValue.length === 0) {
return undefined;
}