diff --git a/packages/config/lib/src/config/config.dart b/packages/config/lib/src/config/config.dart index 66bcc38..cf86657 100644 --- a/packages/config/lib/src/config/config.dart +++ b/packages/config/lib/src/config/config.dart @@ -8,6 +8,7 @@ export 'exceptions.dart'; export 'file_system_options.dart'; export 'multi_config_source.dart'; export 'option_groups.dart'; +export 'option_resolution_data.dart'; export 'option_types.dart'; export 'options.dart'; export 'output_formatting.dart' show formatConfigError; diff --git a/packages/config/lib/src/config/option_groups.dart b/packages/config/lib/src/config/option_groups.dart index 7681896..4854466 100644 --- a/packages/config/lib/src/config/option_groups.dart +++ b/packages/config/lib/src/config/option_groups.dart @@ -1,5 +1,5 @@ import 'exceptions.dart'; -import 'option_resolution.dart'; +import 'option_resolution_data.dart'; import 'options.dart'; enum MutuallyExclusiveMode { @@ -49,7 +49,7 @@ class MutuallyExclusive extends OptionGroup { @override String? validateValues( - final Map optionResolutions, + final Map optionResolutions, ) { final allowDefaults = mode == MutuallyExclusiveMode.allowDefaults; final providedCount = optionResolutions.values diff --git a/packages/config/lib/src/config/option_resolution.dart b/packages/config/lib/src/config/option_resolution.dart index bba7af4..237370a 100644 --- a/packages/config/lib/src/config/option_resolution.dart +++ b/packages/config/lib/src/config/option_resolution.dart @@ -1,11 +1,7 @@ +import 'option_resolution_data.dart'; import 'source_type.dart'; -final class OptionResolution { - final String? stringValue; - final V? value; - final String? error; - final ValueSourceType source; - +final class OptionResolution with OptionResolutionData { const OptionResolution._({ required this.source, this.stringValue, @@ -44,12 +40,15 @@ final class OptionResolution { error: error, ); - /// Whether the option has a proper value (without errors). - bool get hasValue => source != ValueSourceType.noValue && error == null; + @override + final String? stringValue; - /// Whether the option has a value that was specified explicitly (not default). - bool get isSpecified => hasValue && source != ValueSourceType.defaultValue; + @override + final V? value; - /// Whether the option has the default value. - bool get isDefault => hasValue && source == ValueSourceType.defaultValue; + @override + final String? error; + + @override + final ValueSourceType source; } diff --git a/packages/config/lib/src/config/option_resolution_data.dart b/packages/config/lib/src/config/option_resolution_data.dart new file mode 100644 index 0000000..e896ad2 --- /dev/null +++ b/packages/config/lib/src/config/option_resolution_data.dart @@ -0,0 +1,28 @@ +import 'source_type.dart'; + +/// Provides significant metadata about an option once it is resolved. +base mixin OptionResolutionData { + /// The resolved value of the option. + V? get value; + + /// The source from where the option has been resolved. + ValueSourceType get source; + + /// The string value of the option. + String? get stringValue; + + /// Error message, if any, apropos of option resolution. + String? get error; + + /// Whether there was an error during resolving the option. + bool get hasError => error != null; + + /// Whether the option has a proper value (without errors). + bool get hasValue => !hasError && source != ValueSourceType.noValue; + + /// Whether the option has a value that was specified explicitly (not default). + bool get isSpecified => hasValue && source != ValueSourceType.defaultValue; + + /// Whether the option has the default value. + bool get isDefault => hasValue && source == ValueSourceType.defaultValue; +} diff --git a/packages/config/lib/src/config/options.dart b/packages/config/lib/src/config/options.dart index 83b7e6b..6cb7517 100644 --- a/packages/config/lib/src/config/options.dart +++ b/packages/config/lib/src/config/options.dart @@ -7,6 +7,7 @@ import 'configuration.dart'; import 'configuration_broker.dart'; import 'exceptions.dart'; import 'option_resolution.dart'; +import 'option_resolution_data.dart'; import 'source_type.dart'; /// Common interface to enable same treatment for [ConfigOptionBase] @@ -64,7 +65,7 @@ class OptionGroup { /// /// Subclasses may override this method to perform specific validations. String? validateValues( - final Map optionResolutions, + final Map optionResolutions, ) { return null; }