Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/config/lib/src/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/config/lib/src/config/option_groups.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'exceptions.dart';
import 'option_resolution.dart';
import 'option_resolution_data.dart';
import 'options.dart';

enum MutuallyExclusiveMode {
Expand Down Expand Up @@ -49,7 +49,7 @@ class MutuallyExclusive extends OptionGroup {

@override
String? validateValues(
final Map<OptionDefinition, OptionResolution> optionResolutions,
final Map<OptionDefinition, OptionResolutionData> optionResolutions,
) {
final allowDefaults = mode == MutuallyExclusiveMode.allowDefaults;
final providedCount = optionResolutions.values
Expand Down
23 changes: 11 additions & 12 deletions packages/config/lib/src/config/option_resolution.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import 'option_resolution_data.dart';
import 'source_type.dart';

final class OptionResolution<V> {
final String? stringValue;
final V? value;
final String? error;
final ValueSourceType source;

final class OptionResolution<V> with OptionResolutionData<V> {
const OptionResolution._({
required this.source,
this.stringValue,
Expand Down Expand Up @@ -44,12 +40,15 @@ final class OptionResolution<V> {
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;
}
28 changes: 28 additions & 0 deletions packages/config/lib/src/config/option_resolution_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'source_type.dart';

/// Provides significant metadata about an option once it is resolved.
base mixin OptionResolutionData<V> {
/// 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;
}
3 changes: 2 additions & 1 deletion packages/config/lib/src/config/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -64,7 +65,7 @@ class OptionGroup {
///
/// Subclasses may override this method to perform specific validations.
String? validateValues(
final Map<OptionDefinition, OptionResolution> optionResolutions,
final Map<OptionDefinition, OptionResolutionData> optionResolutions,
) {
return null;
}
Expand Down