Skip to content

Commit 81d2ca8

Browse files
Renaming: All value sources but constants include calculations
1 parent 8b36b4b commit 81d2ca8

File tree

8 files changed

+20
-25
lines changed

8 files changed

+20
-25
lines changed

src/System.CommandLine.Subsystems.Tests/System.CommandLine.Subsystems.Tests.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
<TargetFrameworks>$(TargetFrameworkForNETSDK)</TargetFrameworks>
55
<GenerateProgramFile>false</GenerateProgramFile>
66
<DefaultExcludesInProjectFolder>$(DefaultExcludesInProjectFolder);TestApps\**</DefaultExcludesInProjectFolder>
7-
<OutputType>Library</OutputType>
87
<ImplicitUsings>enable</ImplicitUsings>
98
<Nullable>annotations</Nullable>
10-
<!--
11-
<Nullable>enable</Nullable>
12-
-->
139
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
1410
</PropertyGroup>
1511

src/System.CommandLine.Subsystems.Tests/ValueSourceTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void CalculatedValueSource_from_extension_produces_value()
108108
public void RelativeToSymbolValueSource_produces_value_that_was_set()
109109
{
110110
var option = new CliOption<int>("-a");
111-
var valueSource = new RelativeToSymbolValueSource<int>(option);
111+
var valueSource = new SymbolValueSource<int>(option);
112112

113113
var found = valueSource.TryGetTypedValue(EmptyPipelineResult("-a 42", option), out var value);
114114

@@ -137,7 +137,7 @@ public void RelativeToSymbolValueSource_implicitly_converted_produces_value_that
137137
public void RelativeToSymbolValueSource_from_extension_produces_value_that_was_set()
138138
{
139139
var option = new CliOption<int>("-a");
140-
var valueSource = new RelativeToSymbolValueSource<int>(option);
140+
var valueSource = new SymbolValueSource<int>(option);
141141

142142
var found = valueSource.TryGetTypedValue(EmptyPipelineResult("-a 42", option), out var value);
143143

@@ -151,7 +151,7 @@ public void RelativeToSymbolValueSource_from_extension_produces_value_that_was_s
151151
public void RelativeToEnvironmentVariableValueSource_produces_value_that_was_set()
152152
{
153153
var envName = "SYSTEM_COMMANDLINE_TESTING";
154-
var valueSource = new RelativeToEnvironmentVariableValueSource<int>(envName);
154+
var valueSource = new EnvironmentVariableValueSource<int>(envName);
155155

156156
Environment.SetEnvironmentVariable(envName, "42");
157157
var found = valueSource.TryGetTypedValue(EmptyPipelineResult(), out var value);
@@ -184,7 +184,7 @@ public void RelativeToEnvironmentVariableValueSource_from_extension_produces_val
184184
public void RelativeToSymbolValueSource_false_if_other_symbol_has_no_default_and_is_missing()
185185
{
186186
var option = new CliOption<int>("-a");
187-
var valueSource = new RelativeToSymbolValueSource<int>(option);
187+
var valueSource = new SymbolValueSource<int>(option);
188188

189189
var found = valueSource.TryGetTypedValue(EmptyPipelineResult("", option), out var value);
190190
found.Should()
@@ -197,7 +197,7 @@ public void RelativeToSymbolValueSource_false_if_other_symbol_has_no_default_and
197197
public void RelativeToEnvironmentVariable_false_if_environment_variable_missing()
198198
{
199199
var envName = "SYSTEM_COMMANDLINE_TESTING";
200-
var valueSource = new RelativeToEnvironmentVariableValueSource<int>(envName);
200+
var valueSource = new EnvironmentVariableValueSource<int>(envName);
201201

202202
var found = valueSource.TryGetTypedValue(EmptyPipelineResult(), out var value);
203203

src/System.CommandLine.Subsystems/Validation/ValidationContext.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.CommandLine.Parsing;
55
using System.CommandLine.ValueSources;
6-
using static System.Runtime.InteropServices.JavaScript.JSType;
76

87
namespace System.CommandLine.Validation;
98

src/System.CommandLine.Subsystems/ValueSources/RelativeToSymbolsValueSource.cs src/System.CommandLine.Subsystems/ValueSources/CollectionValueSource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace System.CommandLine.ValueSources;
1212
/// <param name="calculation">A delegate that returns the requested type.</param>
1313
/// <param name="description">The description of this value, used to clarify the intent of the values that appear in error messages.</param>
1414
// TODO: Do we want this to be an aggregate, such that you could build a type from other symbols, calcs and env variables. Ooo aahh
15-
public sealed class RelativeToSymbolsValueSource<T>
15+
public sealed class CollectionValueSource<T>
1616
: ValueSource<T>
1717
{
18-
internal RelativeToSymbolsValueSource(
18+
internal CollectionValueSource(
1919
Func<IEnumerable<object?>, (bool success, T? value)> calculation,
2020
bool onlyUserEnteredValues = false,
2121
string? description = null,

src/System.CommandLine.Subsystems/ValueSources/RelativeToEnvironmentVariableValueSource.cs src/System.CommandLine.Subsystems/ValueSources/EnvironmentVariableValueSource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace System.CommandLine.ValueSources;
1111
/// <param name="environmentVariableName">The name of then environment variable. Note that for some systems, this is case sensitive.</param>
1212
/// <param name="calculation">A delegate that returns the requested type. If it is not specified, standard type conversions are used.</param>
1313
/// <param name="description">The description of this value, used to clarify the intent of the values that appear in error messages.</param>
14-
public sealed class RelativeToEnvironmentVariableValueSource<T>
14+
public sealed class EnvironmentVariableValueSource<T>
1515
: ValueSource<T>
1616
{
17-
internal RelativeToEnvironmentVariableValueSource(
17+
internal EnvironmentVariableValueSource(
1818
string environmentVariableName,
1919
Func<string?, (bool success, T? value)>? calculation = null,
2020
string? description = null)

src/System.CommandLine.Subsystems/ValueSources/AggregateValueSource.cs src/System.CommandLine.Subsystems/ValueSources/FallbackValueSource.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace System.CommandLine.ValueSources;
55

6-
public sealed class AggregateValueSource<T> : ValueSource<T>
6+
public sealed class FallbackValueSource<T> : ValueSource<T>
77
{
88
private List<ValueSource<T>> valueSources = [];
99

10-
internal AggregateValueSource(ValueSource<T> firstSource,
10+
internal FallbackValueSource(ValueSource<T> firstSource,
1111
ValueSource<T> secondSource,
1212
string? description = null,
1313
params ValueSource<T>[] otherSources)
@@ -45,10 +45,10 @@ internal static int GetPrecedence(ValueSource<T> source)
4545
return source switch
4646
{
4747
SimpleValueSource<T> => 0,
48-
RelativeToSymbolValueSource<T> => 1,
48+
SymbolValueSource<T> => 1,
4949
CalculatedValueSource<T> => 2,
5050
//RelativeToConfigurationValueSource<T> => 3,
51-
RelativeToEnvironmentVariableValueSource<T> => 4,
51+
EnvironmentVariableValueSource<T> => 4,
5252
_ => 5
5353
};
5454
}

src/System.CommandLine.Subsystems/ValueSources/RelativeToSymbolValueSource.cs src/System.CommandLine.Subsystems/ValueSources/SymbolValueSource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace System.CommandLine.ValueSources;
1111
/// <param name="otherSymbol">The option or argument to return, with the calculation supplied if it is not null.</param>
1212
/// <param name="calculation">A delegate that returns the requested type.</param>
1313
/// <param name="description">The description of this value, used to clarify the intent of the values that appear in error messages.</param>
14-
public sealed class RelativeToSymbolValueSource<T>
14+
public sealed class SymbolValueSource<T>
1515
: ValueSource<T>
1616
{
1717
// TODO: API differences between this adn RelativeToSymbols are very annoying
18-
internal RelativeToSymbolValueSource(
18+
internal SymbolValueSource(
1919
CliValueSymbol otherSymbol,
2020
Func<object?, (bool success, T? value)>? calculation = null,
2121
bool onlyUserEnteredValues = false,

src/System.CommandLine.Subsystems/ValueSources/ValueSource.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ public static ValueSource<T> Create<T>(CliValueSymbol otherSymbol,
3434
Func<object?, (bool success, T? value)>? calculation = null,
3535
bool userEnteredValueOnly = false,
3636
string? description = null)
37-
=> new RelativeToSymbolValueSource<T>(otherSymbol, calculation, userEnteredValueOnly, description);
37+
=> new SymbolValueSource<T>(otherSymbol, calculation, userEnteredValueOnly, description);
3838

3939
public static ValueSource<T> Create<T>(
4040
Func<IEnumerable<object?>, (bool success, T? value)> calculation,
4141
bool userEnteredValueOnly = false,
4242
string? description = null,
4343
params CliValueSymbol[] otherSymbols)
44-
=> new RelativeToSymbolsValueSource<T>(calculation, userEnteredValueOnly, description, otherSymbols);
44+
=> new CollectionValueSource<T>(calculation, userEnteredValueOnly, description, otherSymbols);
4545

4646
public static ValueSource<T> Create<T>(ValueSource<T> firstSource,
4747
ValueSource<T> secondSource,
4848
string? description = null,
4949
params ValueSource<T>[] otherSources)
50-
=> new AggregateValueSource<T>(firstSource, secondSource, description, otherSources);
50+
=> new FallbackValueSource<T>(firstSource, secondSource, description, otherSources);
5151

5252
public static ValueSource<T> CreateFromEnvironmentVariable<T>(string environmentVariableName,
5353
Func<string?, (bool success, T? value)>? calculation = null,
5454
string? description = null)
55-
=> new RelativeToEnvironmentVariableValueSource<T>(environmentVariableName, calculation, description);
55+
=> new EnvironmentVariableValueSource<T>(environmentVariableName, calculation, description);
5656
}
5757

5858
// TODO: Determine philosophy for custom value sources and whether they can build on existing sources.
@@ -84,7 +84,7 @@ public override bool TryGetValue(PipelineResult pipelineResult,
8484

8585
public static implicit operator ValueSource<T>(T value) => new SimpleValueSource<T>(value);
8686
public static implicit operator ValueSource<T>(Func<(bool success, T? value)> calculated) => new CalculatedValueSource<T>(calculated);
87-
public static implicit operator ValueSource<T>(CliValueSymbol symbol) => new RelativeToSymbolValueSource<T>(symbol);
87+
public static implicit operator ValueSource<T>(CliValueSymbol symbol) => new SymbolValueSource<T>(symbol);
8888
// Environment variable does not have an explicit operator, because converting to string was too broad
8989
}
9090

0 commit comments

Comments
 (0)