Skip to content

Commit b40ebf6

Browse files
authored
rename ParseDiagramDirective To DiagramDirective (#2135)
1 parent 6a1b077 commit b40ebf6

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ System.CommandLine
116116
public static class CompletionSourceExtensions
117117
public static System.Void Add(this System.Collections.Generic.List<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
118118
public static System.Void Add(this System.Collections.Generic.List<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.String[] completions)
119+
public class DiagramDirective : CliDirective
120+
.ctor()
121+
public CliAction Action { get; set; }
122+
public System.Int32 ParseErrorReturnValue { get; set; }
119123
public class EnvironmentVariablesDirective : CliDirective
120124
.ctor()
121125
public CliAction Action { get; set; }
@@ -124,10 +128,6 @@ System.CommandLine
124128
public static CliOption<System.IO.DirectoryInfo> AcceptExistingOnly(this CliOption<System.IO.DirectoryInfo> option)
125129
public static CliOption<System.IO.FileSystemInfo> AcceptExistingOnly(this CliOption<System.IO.FileSystemInfo> option)
126130
public static CliOption<T> AcceptExistingOnly<T>(this CliOption<T> option)
127-
public class ParseDiagramDirective : CliDirective
128-
.ctor()
129-
public CliAction Action { get; set; }
130-
public System.Int32 ParseErrorReturnValue { get; set; }
131131
public class ParseResult
132132
public CliAction Action { get; }
133133
public System.CommandLine.Parsing.CommandResult CommandResult { get; }

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_ParseResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Perf_Parser_ParseResult()
2727

2828
_configuration = new CliConfiguration(new CliRootCommand { option })
2929
{
30-
Directives = { new ParseDiagramDirective() },
30+
Directives = { new DiagramDirective() },
3131
Output = _output
3232
};
3333
}

src/System.CommandLine.Suggest/SuggestionDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public SuggestionDispatcher(ISuggestionRegistration suggestionRegistration, ISug
7575
{
7676
Directives =
7777
{
78-
new ParseDiagramDirective(),
78+
new DiagramDirective(),
7979
new SuggestDirective(),
8080
}
8181
};

src/System.CommandLine.Tests/ParseDirectiveTests.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
namespace System.CommandLine.Tests
1111
{
12-
public class ParseDirectiveTests
12+
public class DiagramDirectiveTests
1313
{
1414
private readonly ITestOutputHelper output;
1515

16-
public ParseDirectiveTests(ITestOutputHelper output)
16+
public DiagramDirectiveTests(ITestOutputHelper output)
1717
{
1818
this.output = output;
1919
}
2020

2121
[Fact]
22-
public async Task Parse_directive_writes_parse_diagram()
22+
public async Task Diagram_directive_writes_parse_diagram()
2323
{
2424
var rootCommand = new CliRootCommand();
2525
var subcommand = new CliCommand("subcommand");
@@ -30,10 +30,10 @@ public async Task Parse_directive_writes_parse_diagram()
3030
CliConfiguration config = new(rootCommand)
3131
{
3232
Output = new StringWriter(),
33-
Directives = { new ParseDiagramDirective() }
33+
Directives = { new DiagramDirective() }
3434
};
3535

36-
var result = rootCommand.Parse("[parse] subcommand -c 34 --nonexistent wat", config);
36+
var result = rootCommand.Parse("[diagram] subcommand -c 34 --nonexistent wat", config);
3737

3838
output.WriteLine(result.Diagram());
3939

@@ -46,17 +46,17 @@ public async Task Parse_directive_writes_parse_diagram()
4646
}
4747

4848
[Fact]
49-
public async Task When_parse_directive_is_used_the_help_is_not_displayed()
49+
public async Task When_diagram_directive_is_used_the_help_is_not_displayed()
5050
{
5151
CliRootCommand rootCommand = new ();
5252

5353
CliConfiguration config = new(rootCommand)
5454
{
5555
Output = new StringWriter(),
56-
Directives = { new ParseDiagramDirective() }
56+
Directives = { new DiagramDirective() }
5757
};
5858

59-
var result = rootCommand.Parse("[parse] --help", config);
59+
var result = rootCommand.Parse("[diagram] --help", config);
6060

6161
output.WriteLine(result.Diagram());
6262

@@ -69,17 +69,17 @@ public async Task When_parse_directive_is_used_the_help_is_not_displayed()
6969
}
7070

7171
[Fact]
72-
public async Task When_parse_directive_is_used_the_version_is_not_displayed()
72+
public async Task When_diagram_directive_is_used_the_version_is_not_displayed()
7373
{
7474
CliRootCommand rootCommand = new();
7575

7676
CliConfiguration config = new(rootCommand)
7777
{
7878
Output = new StringWriter(),
79-
Directives = { new ParseDiagramDirective() }
79+
Directives = { new DiagramDirective() }
8080
};
8181

82-
var result = rootCommand.Parse("[parse] --version", config);
82+
var result = rootCommand.Parse("[diagram] --version", config);
8383

8484
output.WriteLine(result.Diagram());
8585

@@ -92,7 +92,7 @@ public async Task When_parse_directive_is_used_the_version_is_not_displayed()
9292
}
9393

9494
[Fact]
95-
public async Task When_there_are_no_errors_then_parse_directive_sets_exit_code_0()
95+
public async Task When_there_are_no_errors_then_diagram_directive_sets_exit_code_0()
9696
{
9797
CliRootCommand command = new ()
9898
{
@@ -102,16 +102,16 @@ public async Task When_there_are_no_errors_then_parse_directive_sets_exit_code_0
102102
CliConfiguration config = new(command)
103103
{
104104
Output = new StringWriter(),
105-
Directives = { new ParseDiagramDirective() }
105+
Directives = { new DiagramDirective() }
106106
};
107107

108-
var exitCode = await command.Parse("[parse] -x 123", config).InvokeAsync();
108+
var exitCode = await command.Parse("[diagram] -x 123", config).InvokeAsync();
109109

110110
exitCode.Should().Be(0);
111111
}
112112

113113
[Fact]
114-
public async Task When_there_are_errors_then_parse_directive_sets_exit_code_1()
114+
public async Task When_there_are_errors_then_diagram_directive_sets_exit_code_1()
115115
{
116116
CliRootCommand command = new()
117117
{
@@ -121,16 +121,16 @@ public async Task When_there_are_errors_then_parse_directive_sets_exit_code_1()
121121
CliConfiguration config = new(command)
122122
{
123123
Output = new StringWriter(),
124-
Directives = { new ParseDiagramDirective() }
124+
Directives = { new DiagramDirective() }
125125
};
126126

127-
var exitCode = await command.Parse("[parse] -x not-an-int", config).InvokeAsync();
127+
var exitCode = await command.Parse("[diagram] -x not-an-int", config).InvokeAsync();
128128

129129
exitCode.Should().Be(1);
130130
}
131131

132132
[Fact]
133-
public async Task When_there_are_errors_then_parse_directive_sets_exit_code_to_custom_value()
133+
public async Task When_there_are_errors_then_diagram_directive_sets_exit_code_to_custom_value()
134134
{
135135
CliRootCommand command = new ()
136136
{
@@ -140,13 +140,13 @@ public async Task When_there_are_errors_then_parse_directive_sets_exit_code_to_c
140140
CliConfiguration config = new(command)
141141
{
142142
Output = new StringWriter(),
143-
Directives = { new ParseDiagramDirective
143+
Directives = { new DiagramDirective
144144
{
145145
ParseErrorReturnValue = 42
146146
} }
147147
};
148148

149-
int exitCode = await config.InvokeAsync("[parse] -x not-an-int");
149+
int exitCode = await config.InvokeAsync("[diagram] -x not-an-int");
150150

151151
exitCode.Should().Be(42);
152152
}

src/System.CommandLine.Tests/Utility/ParseResultExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal static string Diagram(this ParseResult parseResult)
1111
try
1212
{
1313
parseResult.Configuration.Output = new StringWriter();
14-
new ParseDiagramDirective().Action.Invoke(parseResult);
14+
new DiagramDirective().Action.Invoke(parseResult);
1515
return parseResult.Configuration.Output.ToString()
1616
.TrimEnd(); // the directive adds a new line, tests that used to rely on Diagram extension method don't expect it
1717
}

src/System.CommandLine/ParseDiagramDirective.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
namespace System.CommandLine
44
{
55
/// <summary>
6-
/// Enables the use of the <c>[parse]</c> directive, which when specified on the command line will short
6+
/// Enables the use of the <c>[diagram]</c> directive, which when specified on the command line will short
77
/// circuit normal command handling and display a diagram explaining the parse result for the command line input.
88
/// </summary>
9-
public sealed class ParseDiagramDirective : CliDirective
9+
public sealed class DiagramDirective : CliDirective
1010
{
1111
private CliAction? _action;
1212

1313
/// <summary>
14-
/// Writes a diagram of the parse result to the console.
14+
/// Writes a diagram of the parse result to the output.
1515
/// </summary>
16-
public ParseDiagramDirective() : base("parse")
16+
public DiagramDirective() : base("diagram")
1717
{
1818
}
1919

2020
/// <inheritdoc />
2121
public override CliAction? Action
2222
{
23-
get => _action ??= new ParseDiagramAction(ParseErrorReturnValue);
23+
get => _action ??= new DiagramAction(ParseErrorReturnValue);
2424
set => _action = value ?? throw new ArgumentNullException(nameof(value));
2525
}
2626

src/System.CommandLine/ParseResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void Populate<TSymbol>(Dictionary<string, SymbolResult?> cache, IList<TSymbol> s
194194
}
195195

196196
/// <inheritdoc />
197-
public override string ToString() => ParseDiagramAction.Diagram(this).ToString();
197+
public override string ToString() => DiagramAction.Diagram(this).ToString();
198198

199199
/// <summary>
200200
/// Gets the result, if any, for the specified argument.

src/System.CommandLine/Parsing/ParseDiagramAction.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
namespace System.CommandLine.Parsing
1212
{
1313
/// <summary>
14-
/// Implements the <c>[parse]</c> directive action, which when specified on the command line
14+
/// Implements the <c>[diagram]</c> directive action, which when specified on the command line
1515
/// will short circuit normal command handling and display a diagram explaining the parse result for the command line input.
1616
/// </summary>
17-
internal sealed class ParseDiagramAction : CliAction
17+
internal sealed class DiagramAction : CliAction
1818
{
1919
private readonly int _parseErrorReturnValue;
2020

21-
internal ParseDiagramAction(int parseErrorReturnValue) => _parseErrorReturnValue = parseErrorReturnValue;
21+
internal DiagramAction(int parseErrorReturnValue) => _parseErrorReturnValue = parseErrorReturnValue;
2222

2323
public override int Invoke(ParseResult parseResult)
2424
{
@@ -79,7 +79,7 @@ private static void Diagram(
7979

8080
switch (symbolResult)
8181
{
82-
case DirectiveResult directiveResult when directiveResult.Directive is not ParseDiagramDirective:
82+
case DirectiveResult directiveResult when directiveResult.Directive is not DiagramDirective:
8383
break;
8484
case ArgumentResult argumentResult:
8585
{

src/System.CommandLine/Parsing/ParseOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void ParseDirective()
321321

322322
_action = directive.Action;
323323

324-
if (directive is ParseDiagramDirective)
324+
if (directive is DiagramDirective)
325325
{
326326
_isParseRequested = true;
327327
}

0 commit comments

Comments
 (0)