resolveValue method

OptionResolution<bool> resolveValue(
  1. Configuration<OptionDefinition> cfg, {
  2. ArgResults? args,
  3. Iterator<String>? posArgs,
  4. Map<String, String>? env,
  5. ConfigurationBroker<OptionDefinition>? configBroker,
})
inherited

////////////////// Returns the resolved value of this configuration option from the provided context. For options with positional arguments this must be invoked in ascending position order. Returns the result with the resolved value or error.

This method is intended for internal use.

Implementation

// Value resolution

/// Returns the resolved value of this configuration option from the provided context.
/// For options with positional arguments this must be invoked in ascending position order.
/// Returns the result with the resolved value or error.
///
/// This method is intended for internal use.
OptionResolution<V> resolveValue(
  final Configuration cfg, {
  final ArgResults? args,
  final Iterator<String>? posArgs,
  final Map<String, String>? env,
  final ConfigurationBroker? configBroker,
}) {
  OptionResolution<V> res;
  try {
    res = _doResolve(
      cfg,
      args: args,
      posArgs: posArgs,
      env: env,
      configBroker: configBroker,
    );
  } on Exception catch (e) {
    return OptionResolution.error(
      'Failed to resolve ${option.qualifiedString()}: $e',
    );
  }

  if (res.error != null) {
    return res;
  }

  final stringValue = res.stringValue;
  if (stringValue != null) {
    // value provided by string-based config source, parse to the designated type
    try {
      res = res.copyWithValue(
        option.option.valueParser.parse(stringValue),
      );
    } on FormatException catch (e) {
      return res.copyWithError(
        _makeFormatErrorMessage(e),
      );
    }
  }

  final error = validateOptionValue(res.value);
  if (error != null) return res.copyWithError(error);

  return res;
}