Skip to content

Commit 0933deb

Browse files
Work on tests and removed Set/GetDefaultValue
1 parent abb1226 commit 0933deb

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,31 @@ public void Value_is_always_activated()
3030
isActive.Should().BeTrue();
3131
}
3232

33-
[Fact]
33+
[Fact(Skip ="WIP")]
3434
public void ValueSubsystem_returns_values_that_are_entered()
3535
{
36+
var consoleHack = new ConsoleHack().RedirectToBuffer(true);
37+
var pipeline = Pipeline.Create();
38+
CliOption<int> option1 = new CliOption<int>("--intValue");
3639
CliRootCommand rootCommand = [
3740
new CliCommand("x")
3841
{
39-
new CliOption<int>("--intValue"),
40-
new CliOption<string>("--stringValue"),
41-
new CliOption<bool>("--boolValue")
42+
option1
4243
}];
4344
var configuration = new CliConfiguration(rootCommand);
44-
var subsystem = new ValueSubsystem();
4545
const int expected1 = 42;
46-
const string expected2 = "43";
47-
var input = $"x --intValue {expected1} --stringValue \"{expected2}\" --boolValue";
48-
var args = CliParser.SplitCommandLine(input).ToList();
46+
var input = $"x --intValue {expected1}";
4947

50-
Subsystem.Initialize(subsystem, configuration, args);
51-
var parseResult = CliParser.Parse(rootCommand, input, configuration);
48+
pipeline.Parse(configuration, input);
49+
pipeline.Execute(configuration, input, consoleHack);
50+
51+
pipeline.Value.GetValue<int>(option1).Should().Be(expected1);
52+
}
53+
54+
55+
[Fact(Skip = "WIP")]
56+
public void ValueSubsystem_returns_default_value_when_no_value_is_entered()
57+
{
5258

53-
parseResult.GetValue<int>("--intValue").Should().Be(expected1);
54-
parseResult.GetValue<string>("--stringValue").Should().Be(expected2);
55-
parseResult.GetValue<bool>("--boolValue").Should().Be(true);
5659
}
5760
}

src/System.CommandLine.Subsystems/ValueSubsystem.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public ValueSubsystem(IAnnotationProvider? annotationProvider = null)
1818
: base(ValueAnnotations.Prefix, SubsystemKind.Version, annotationProvider)
1919
{ }
2020

21-
internal void SetDefaultValue(CliSymbol symbol, object? defaultValue)
22-
=> SetAnnotation(symbol, ValueAnnotations.DefaultValue, defaultValue);
23-
internal object? GetDefaultValue(CliSymbol symbol)
24-
=> TryGetAnnotation(symbol, ValueAnnotations.DefaultValue, out var defaultValue)
25-
? defaultValue
26-
: "";
27-
internal bool TryGetDefaultValue<T>(CliSymbol symbol, out T? defaultValue)
21+
//internal void SetDefaultValue(CliSymbol symbol, object? defaultValue)
22+
// => SetAnnotation(symbol, ValueAnnotations.DefaultValue, defaultValue);
23+
//internal object? GetDefaultValue(CliSymbol symbol)
24+
// => TryGetAnnotation(symbol, ValueAnnotations.DefaultValue, out var defaultValue)
25+
// ? defaultValue
26+
// : "";
27+
private bool TryGetDefaultValue<T>(CliSymbol symbol, out T? defaultValue)
2828
{
2929
if (TryGetAnnotation(symbol, ValueAnnotations.Value, out var objectValue))
3030
{

0 commit comments

Comments
 (0)