Skip to content

Commit 9395d84

Browse files
Merge pull request #2431 from KathleenDollard/powderhouse-kad-removed-fluent-returns
Powderhouse removed CliExit and fluent style for pipeline execution
2 parents 2946046 + 7013b47 commit 9395d84

16 files changed

+79
-108
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ internal class AlternateSubsystems
1010
{
1111
internal class AlternateVersion : VersionSubsystem
1212
{
13-
protected override CliExit Execute(PipelineResult pipelineResult)
13+
protected override void Execute(PipelineResult pipelineResult)
1414
{
1515
pipelineResult.ConsoleHack.WriteLine($"***{CliExecutable.ExecutableVersion}***");
16-
pipelineResult.AlreadyHandled = true;
17-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
16+
pipelineResult.SetSuccess();
1817
}
1918
}
2019

@@ -29,12 +28,12 @@ public VersionThatUsesHelpData(CliSymbol symbol)
2928

3029
private CliSymbol Symbol { get; }
3130

32-
protected override CliExit Execute(PipelineResult pipelineResult)
31+
protected override void Execute(PipelineResult pipelineResult)
3332
{
3433
TryGetAnnotation(Symbol, HelpAnnotations.Description, out string? description);
3534
pipelineResult.ConsoleHack.WriteLine(description);
3635
pipelineResult.AlreadyHandled = true;
37-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
36+
pipelineResult.SetSuccess();
3837
}
3938
}
4039

@@ -44,23 +43,23 @@ internal class VersionWithInitializeAndTeardown : VersionSubsystem
4443
internal bool ExecutionWasRun;
4544
internal bool TeardownWasRun;
4645

47-
protected override CliConfiguration Initialize(InitializationContext context)
46+
protected override void Initialize(InitializationContext context)
4847
{
48+
base.Initialize(context);
4949
// marker hack needed because ConsoleHack not available in initialization
5050
InitializationWasRun = true;
51-
return base.Initialize(context);
5251
}
5352

54-
protected override CliExit Execute(PipelineResult pipelineResult)
53+
protected override void Execute(PipelineResult pipelineResult)
5554
{
5655
ExecutionWasRun = true;
57-
return base.Execute(pipelineResult);
56+
base.Execute(pipelineResult);
5857
}
5958

60-
protected override CliExit TearDown(CliExit cliExit)
59+
protected override void TearDown(PipelineResult pipelineResult)
6160
{
6261
TeardownWasRun = true;
63-
return base.TearDown(cliExit);
62+
base.TearDown(pipelineResult);
6463
}
6564
}
6665

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Subsystem_runs_in_pipeline_only_when_requested(string input, bool sh
4343
var exit = pipeline.Execute(GetNewTestConfiguration(), input, console);
4444

4545
exit.ExitCode.Should().Be(0);
46-
exit.Handled.Should().Be(shouldRun);
46+
exit.AlreadyHandled.Should().Be(shouldRun);
4747
if (shouldRun)
4848
{
4949
console.GetBuffer().Trim().Should().Be(TestData.AssemblyVersionString);
@@ -61,7 +61,7 @@ public void Subsystem_runs_with_explicit_parse_only_when_requested(string input,
6161
var exit = pipeline.Execute(result, input, console);
6262

6363
exit.ExitCode.Should().Be(0);
64-
exit.Handled.Should().Be(shouldRun);
64+
exit.AlreadyHandled.Should().Be(shouldRun);
6565
if (shouldRun)
6666
{
6767
console.GetBuffer().Trim().Should().Be(TestData.AssemblyVersionString);
@@ -79,7 +79,7 @@ public void Subsystem_runs_initialize_and_teardown_when_requested(string input,
7979
var exit = pipeline.Execute(GetNewTestConfiguration(), input, console);
8080

8181
exit.ExitCode.Should().Be(0);
82-
exit.Handled.Should().Be(shouldRun);
82+
exit.AlreadyHandled.Should().Be(shouldRun);
8383
versionSubsystem.InitializationWasRun.Should().BeTrue();
8484
versionSubsystem.ExecutionWasRun.Should().Be(shouldRun);
8585
versionSubsystem.TeardownWasRun.Should().BeTrue();
@@ -109,7 +109,7 @@ public void Subsystem_works_without_pipeline(string input, bool shouldRun)
109109
var exit = Subsystem.Execute(versionSubsystem, parseResult, input, console);
110110
exit.Should().NotBeNull();
111111
exit.ExitCode.Should().Be(0);
112-
exit.Handled.Should().BeTrue();
112+
exit.AlreadyHandled.Should().BeTrue();
113113
console.GetBuffer().Trim().Should().Be(TestData.AssemblyVersionString);
114114
}
115115
}
@@ -132,7 +132,7 @@ public void Subsystem_works_without_pipeline_style2(string input, bool shouldRun
132132
var exit = Subsystem.ExecuteIfNeeded(versionSubsystem, parseResult, input, console);
133133

134134
exit.ExitCode.Should().Be(0);
135-
exit.Handled.Should().Be(shouldRun);
135+
exit.AlreadyHandled.Should().Be(shouldRun);
136136
console.GetBuffer().Trim().Should().Be(expectedVersion);
137137
}
138138

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void When_the_version_option_is_specified_then_the_version_is_written_to_
2626
var exit = pipeline.Execute(configuration, "-v", consoleHack);
2727

2828
exit.ExitCode.Should().Be(0);
29-
exit.Handled.Should().BeTrue();
29+
exit.AlreadyHandled.Should().BeTrue();
3030
consoleHack.GetBuffer().Should().Be($"{version}{newLine}");
3131
}
3232

src/System.CommandLine.Subsystems/CliExit.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/System.CommandLine.Subsystems/CompletionSubsystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ protected internal override bool GetIsActivated(ParseResult? parseResult)
1818
? false
1919
: false;
2020

21-
protected internal override CliExit Execute(PipelineResult pipelineResult)
21+
protected internal override void Execute(PipelineResult pipelineResult)
2222
{
2323
pipelineResult.ConsoleHack.WriteLine("Not yet implemented");
24-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
24+
pipelineResult.SetSuccess();
2525
}
2626
}

src/System.CommandLine.Subsystems/Directives/DiagramSubsystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class DiagramSubsystem( IAnnotationProvider? annotationProvider = null)
1313
//protected internal override bool GetIsActivated(ParseResult? parseResult)
1414
// => parseResult is not null && option is not null && parseResult.GetValue(option);
1515

16-
protected internal override CliExit Execute(PipelineResult pipelineResult)
16+
protected internal override void Execute(PipelineResult pipelineResult)
1717
{
1818
// Gather locations
1919
//var locations = pipelineResult.ParseResult.LocationMap
2020
// .Concat(Map(pipelineResult.ParseResult.Configuration.PreProcessedLocations));
2121

2222
pipelineResult.ConsoleHack.WriteLine("Output diagram");
23-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
23+
pipelineResult.SetSuccess();
2424
}
2525

2626

src/System.CommandLine.Subsystems/Directives/DirectiveSubsystem.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public DirectiveSubsystem(string name, SubsystemKind kind, IAnnotationProvider?
1919
Id = id ?? name;
2020
}
2121

22-
protected internal override CliConfiguration Initialize(InitializationContext context)
22+
protected internal override void Initialize(InitializationContext context)
2323
{
2424
for (int i = 0; i < context.Args.Count; i++)
2525
{
@@ -50,8 +50,6 @@ protected internal override CliConfiguration Initialize(InitializationContext co
5050
break;
5151
}
5252
}
53-
54-
return context.Configuration;
5553
}
5654

5755
protected internal override bool GetIsActivated(ParseResult? parseResult)

src/System.CommandLine.Subsystems/Directives/ResponseSubsystem.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ namespace System.CommandLine.Directives;
99
public class ResponseSubsystem()
1010
: CliSubsystem("Response", SubsystemKind.Response, null)
1111
{
12-
protected internal override CliConfiguration Initialize(InitializationContext context)
13-
{
14-
context.Configuration.ResponseFileTokenReplacer = Replacer;
15-
return context.Configuration;
16-
}
12+
protected internal override void Initialize(InitializationContext context)
13+
=> context.Configuration.ResponseFileTokenReplacer = Replacer;
1714

1815
public static (List<string>? tokens, List<string>? errors) Replacer(string responseSourceName)
1916
{

src/System.CommandLine.Subsystems/ErrorReportingSubsystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ protected internal override bool GetIsActivated(ParseResult? parseResult)
2323
=> parseResult is not null && parseResult.Errors.Any();
2424

2525
// TODO: properly test execute directly when parse result is usable in tests
26-
protected internal override CliExit Execute(PipelineResult pipelineResult)
26+
protected internal override void Execute(PipelineResult pipelineResult)
2727
{
2828
var _ = pipelineResult.ParseResult
2929
?? throw new ArgumentException("The parse result has not been set", nameof(pipelineResult));
3030

3131
Report(pipelineResult.ConsoleHack, pipelineResult.ParseResult.Errors);
3232

33-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
33+
pipelineResult.SetSuccess();
3434
}
3535

3636
public void Report(ConsoleHack consoleHack, IReadOnlyList<ParseError> errors)

src/System.CommandLine.Subsystems/HelpSubsystem.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@ public class HelpSubsystem(IAnnotationProvider? annotationProvider = null)
2424
Arity = ArgumentArity.Zero
2525
};
2626

27-
protected internal override CliConfiguration Initialize(InitializationContext context)
28-
{
29-
context.Configuration.RootCommand.Add(HelpOption);
30-
31-
return context.Configuration;
32-
}
27+
protected internal override void Initialize(InitializationContext context)
28+
=> context.Configuration.RootCommand.Add(HelpOption);
3329

3430
protected internal override bool GetIsActivated(ParseResult? parseResult)
3531
=> parseResult is not null && parseResult.GetValue(HelpOption);
3632

37-
protected internal override CliExit Execute(PipelineResult pipelineResult)
33+
protected internal override void Execute(PipelineResult pipelineResult)
3834
{
3935
// TODO: Match testable output pattern
4036
pipelineResult.ConsoleHack.WriteLine("Help me!");
41-
return CliExit.SuccessfullyHandled(pipelineResult.ParseResult);
37+
pipelineResult.SetSuccess();
4238
}
4339

4440
public bool TryGetDescription (CliSymbol symbol, out string? description)

0 commit comments

Comments
 (0)