valueOrFileContent method
The value of the value option if it is set, otherwise the full contents
of the file given by the valueFile option, decoded as UTF-8.
value and valueFile are expected to belong to valueOptionGroup, as
ValueOption and ValueFileOption do: configuration resolution then
fails with a UsageException if neither or both of them are set, before
runWithConfig is reached.
Throws a StateError if neither option is set, which therefore signals a programming error rather than bad user input.
Implementation
String valueOrFileContent({
required final OptionDefinition<String> value,
required final OptionDefinition<File> valueFile,
}) {
final providedValue = optionalValue(value);
if (providedValue != null) {
return providedValue;
}
final providedFile = optionalValue(valueFile);
if (providedFile != null) {
return providedFile.readAsStringSync();
}
throw StateError('Expected one of the value options to be set.');
}