Skip to content

Commit b878eba

Browse files
Updated on my review-cleanup, better comments, readeonly.
Also updated #2410 to describe
1 parent b883f9f commit b878eba

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/System.CommandLine.Subsystems/Pipeline.cs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ namespace System.CommandLine;
99

1010
public partial class Pipeline
1111
{
12-
// TODO: Consider more phases that have obvious meanings, like first and last
13-
private PipelinePhase<DiagramSubsystem> diagramPhase = new(SubsystemKind.Diagram);
14-
private PipelinePhase<CompletionSubsystem> completionPhase = new(SubsystemKind.Completion);
15-
private PipelinePhase<HelpSubsystem> helpPhase = new(SubsystemKind.Help);
16-
private PipelinePhase<VersionSubsystem> versionPhase = new(SubsystemKind.Version);
17-
private PipelinePhase<ValidationSubsystem> validationPhase = new(SubsystemKind.Validation);
18-
private PipelinePhase<InvocationSubsystem> invocationPhase = new(SubsystemKind.Invocation);
19-
private PipelinePhase<ErrorReportingSubsystem> errorReportingPhase = new(SubsystemKind.ErrorReporting);
20-
// TODO: Consider this naming as it sounds like it is a finishing phase
21-
private readonly IEnumerable<PipelinePhase> phases = [];
12+
private readonly PipelinePhase<DiagramSubsystem> diagramPhase = new(SubsystemKind.Diagram);
13+
private readonly PipelinePhase<CompletionSubsystem> completionPhase = new(SubsystemKind.Completion);
14+
private readonly PipelinePhase<HelpSubsystem> helpPhase = new(SubsystemKind.Help);
15+
private readonly PipelinePhase<VersionSubsystem> versionPhase = new(SubsystemKind.Version);
16+
private readonly PipelinePhase<ValidationSubsystem> validationPhase = new(SubsystemKind.Validation);
17+
private readonly PipelinePhase<InvocationSubsystem> invocationPhase = new(SubsystemKind.Invocation);
18+
private readonly PipelinePhase<ErrorReportingSubsystem> errorReportingPhase = new(SubsystemKind.ErrorReporting);
19+
private readonly IEnumerable<PipelinePhase> phases;
2220

2321
/// <summary>
2422
/// Creates an instance of the pipeline using standard features.
@@ -37,8 +35,7 @@ public static Pipeline Create(HelpSubsystem? help = null,
3735
CompletionSubsystem? completion = null,
3836
DiagramSubsystem? diagram = null,
3937
ErrorReportingSubsystem? errorReporting = null)
40-
{
41-
Pipeline pipeline = new()
38+
=> new()
4239
{
4340
Help = help ?? new HelpSubsystem(),
4441
Version = version ?? new VersionSubsystem(),
@@ -47,10 +44,6 @@ public static Pipeline Create(HelpSubsystem? help = null,
4744
ErrorReporting = errorReporting ?? new ErrorReportingSubsystem(),
4845
};
4946

50-
51-
return pipeline;
52-
}
53-
5447
/// <summary>
5548
/// Creates an instance of the pipeline with no features. Use this if you want to explicitly add features.
5649
/// </summary>
@@ -88,21 +81,21 @@ public bool ResponseFilesEnabled
8881
}
8982

9083
/// <summary>
91-
/// Adds a subsystem. Use the property for the subsystem to replace the standard property. Use this method if you want an an additional subsystem.
84+
/// Adds a subsystem.
9285
/// </summary>
9386
/// <param name="subsystem">The subsystem to add.</param>
9487
/// <param name="timing"><see cref="PhaseTiming.Before"/> indicates that the subsystem should run before all other subsystems in the phase, and <see cref="PhaseTiming.After"/> indicates it should run after other subsystems. The default is <see cref="PhaseTiming.Before"/>.</param>
9588
/// <exception cref="InvalidOperationException"></exception>
9689
/// <remarks>
97-
/// The phase in which the subsystem runs is determined by the subsystem.
90+
/// The phase in which the subsystem runs is determined by the subsystem's 'Kind' property.
91+
/// <br/>
92+
/// To replace one of hte standard subsystems, use the `Pipeline.(subsystem)` property, such as `myPipeline.Help = new OtherHelp();`
9893
/// </remarks>
9994
public void AddSubsystem(CliSubsystem subsystem, PhaseTiming timing = PhaseTiming.Before)
10095
{
10196
switch (subsystem.Kind)
10297
{
103-
// TODO: Determine how Other should work. Do we have a kind and a phase? Perhaps just for Other subsystems. I think it is helpful to know it is something unforeseen
10498
case SubsystemKind.Other:
105-
break;
10699
case SubsystemKind.Response:
107100
case SubsystemKind.Value:
108101
throw new InvalidOperationException($"You cannot add subsystems to {subsystem.Kind}");
@@ -118,6 +111,12 @@ public void AddSubsystem(CliSubsystem subsystem, PhaseTiming timing = PhaseTimin
118111
case SubsystemKind.Version:
119112
versionPhase.AddSubsystem(subsystem, timing);
120113
break;
114+
case SubsystemKind.Validation:
115+
validationPhase.AddSubsystem(subsystem, timing);
116+
break;
117+
case SubsystemKind.Invocation:
118+
invocationPhase.AddSubsystem(subsystem, timing);
119+
break;
121120
case SubsystemKind.ErrorReporting:
122121
errorReportingPhase.AddSubsystem(subsystem, timing);
123122
break;
@@ -140,7 +139,6 @@ public CompletionSubsystem? Completion
140139
{
141140
get => completionPhase.Subsystem;
142141
set => completionPhase.Subsystem = value;
143-
144142
}
145143

146144
/// <summary>
@@ -150,7 +148,6 @@ public HelpSubsystem? Help
150148
{
151149
get => helpPhase.Subsystem;
152150
set => helpPhase.Subsystem = value;
153-
154151
}
155152

156153
/// <summary>
@@ -171,6 +168,7 @@ public ErrorReportingSubsystem? ErrorReporting
171168
set => errorReportingPhase.Subsystem = value;
172169
}
173170

171+
// TODO: Consider whether replacing the validation subsystem is valuable
174172
/// <summary>
175173
/// Sets or gets the validation subsystem
176174
/// </summary>
@@ -180,7 +178,7 @@ public ValidationSubsystem? Validation
180178
set => validationPhase.Subsystem = value;
181179
}
182180

183-
181+
// TODO: Consider whether replacing the invocation subsystem is valuable
184182
/// <summary>
185183
/// Sets or gets the invocation subsystem
186184
/// </summary>
@@ -190,15 +188,13 @@ public InvocationSubsystem? Invocation
190188
set => invocationPhase.Subsystem = value;
191189
}
192190

193-
194-
// TODO: Are there use cases to replace this? Do we want new default values to require a new ValueSubsystem, which would block getting response providers from two sources.
195191
/// <summary>
196-
/// Sets or gets the value subsystem which manages entered and default values.
192+
/// Gets the value subsystem which manages entered and default values.
197193
/// </summary>
198194
public ValueSubsystem Value { get; }
199195

200196
/// <summary>
201-
/// Sets or gets the response file subsystem
197+
/// Gets the response file subsystem
202198
/// </summary>
203199
public ResponseSubsystem Response { get; }
204200

0 commit comments

Comments
 (0)