findOption method

GlobalOption? findOption({
  1. String? enumName,
  2. String? argName,
  3. int? argPos,
  4. String? envName,
  5. String? configKey,
})
inherited

Returns the option definition for the given enum name, or any provided argument name, position, environment variable name, or configuration key. The first one that matches is returned, or null if none match.

The recommended practice is to define options as enums and identify them by the enum name.

Implementation

O? findOption({
  final String? enumName,
  final String? argName,
  final int? argPos,
  final String? envName,
  final String? configKey,
}) {
  return _options.firstWhereOrNull((final o) {
    return (enumName != null && o is Enum && (o as Enum).name == enumName) ||
        (argName != null && o.option.argName == argName) ||
        (argPos != null && o.option.argPos == argPos) ||
        (envName != null && o.option.envName == envName) ||
        (configKey != null && o.option.configKey == configKey);
  });
}