getInput function

String getInput({
  1. required String name,
  2. InputOptions options = const InputOptions(),
})

Gets the value of an input.

Unless trimWhitespace is set to false in InputOptions, the value is also trimmed. Returns an empty string if the value is not defined.

Implementation

String getInput({
  required String name,
  InputOptions options = const InputOptions(),
}) {
  final key = 'INPUT_${name.replaceAll(' ', '_').toUpperCase()}';

  final val = environmentVariables[key] ?? '';
  if (options.required && val.isEmpty) {
    throw ArgumentError('Input required and not supplied: $name');
  }

  return options.trimWhitespace ? val.trim() : val;
}