value<V> method
V
value<V>(
- OptionDefinition<
V> option
inherited
Returns the value of a configuration option that is guaranteed to be non-null.
Throws UsageException
if the option is mandatory and no value is provided.
If called for an option that is neither mandatory nor has defaults,
StateError is thrown. See also optionalValue
.
Throws ArgumentError if the option is unknown.
Implementation
V value<V>(final OptionDefinition<V> option) {
if (!(option.option.mandatory ||
option.option.fromDefault != null ||
option.option.defaultsTo != null)) {
throw StateError(
"Can't invoke non-nullable value() for ${option.qualifiedString()} "
'which is neither mandatory nor has a default value.');
}
final val = optionalValue(option);
if (val != null) return val;
throw InvalidParseStateError(
'No value available for ${option.qualifiedString()} due to previous errors');
}