Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out parseYAMLBoolean from core.getBooleanInput #1302

Open
andreasabel opened this issue Jan 5, 2023 · 0 comments
Open

Factor out parseYAMLBoolean from core.getBooleanInput #1302

andreasabel opened this issue Jan 5, 2023 · 0 comments

Comments

@andreasabel
Copy link

andreasabel commented Jan 5, 2023

The (relatively new) function getBooleanInput in core bundles the parsing of a YAML boolean with getInput. However, that parsing functionality would be useful on its own.
I suggest to factor out function parseYAMLBoolean(text: string): boolean from getBooleanInput such that the latter is essentially just a composition of parseYAMLBoolean and getInput:

function getBooleanInput(name: string, options?: InputOptions): boolean { 
  try {
    return parseYAMLBoolean(getInput(name, options));
  } catch ... {
   // Throw the informative error referring to "name" here
  }
}

* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
* The return value is also in boolean type.
* ref: https://yaml.org/spec/1.2/spec.html#id2804923
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns boolean
*/
export function getBooleanInput(name: string, options?: InputOptions): boolean {
const trueValue = ['true', 'True', 'TRUE']
const falseValue = ['false', 'False', 'FALSE']
const val = getInput(name, options)
if (trueValue.includes(val)) return true
if (falseValue.includes(val)) return false
throw new TypeError(
`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant