operator [] method
Returns the parsed or default command-line option named name
.
name
must be a valid option name in the parser.
Note
Callers should prefer using the more strongly typed methods - flag for flags, option for options, and multiOption for multi-options.
Implementation
dynamic operator [](String name) {
if (!_parser.options.containsKey(name)) {
throw ArgumentError('Could not find an option named "--$name".');
}
final option = _parser.options[name]!;
if (option.mandatory && !_parsed.containsKey(name)) {
throw ArgumentError('Option $name is mandatory.');
}
return option.valueOrDefault(_parsed[name]);
}