Skip to content

Commit fe66356

Browse files
authored
Rename Option/CommandResult.Token to IdentifierToken (#2122)
* rename Option.Token to IdentifierToken, fixes #2015 * do the same for CommandResult
1 parent 72ace16 commit fe66356

File tree

9 files changed

+17
-17
lines changed

9 files changed

+17
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ System.CommandLine.Parsing
245245
public class CommandResult : SymbolResult
246246
public System.Collections.Generic.IEnumerable<SymbolResult> Children { get; }
247247
public System.CommandLine.Command Command { get; }
248-
public Token Token { get; }
248+
public Token IdentifierToken { get; }
249249
public System.String ToString()
250250
public class DirectiveResult : SymbolResult
251251
public System.CommandLine.Directive Directive { get; }
252252
public Token Token { get; }
253253
public System.Collections.Generic.IReadOnlyList<System.String> Values { get; }
254254
public class OptionResult : SymbolResult
255+
public Token IdentifierToken { get; }
255256
public System.Boolean IsImplicit { get; }
256257
public System.CommandLine.Option Option { get; }
257-
public Token Token { get; }
258258
public T GetValueOrDefault<T>()
259259
public System.String ToString()
260260
public class ParseError

src/System.CommandLine.Tests/ParserTests.RootCommandAndArg0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void When_parsing_an_unsplit_string_then_input_a_full_path_to_an_executab
7979

8080
var result2 = command.Parse($"\"{RootCommand.ExecutablePath}\" inner -x hello");
8181

82-
result2.RootCommandResult.Token.Value.Should().Be(RootCommand.ExecutablePath);
82+
result2.RootCommandResult.IdentifierToken.Value.Should().Be(RootCommand.ExecutablePath);
8383
}
8484

8585
[Fact]

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ public void When_an_option_with_a_default_value_is_not_matched_then_there_are_no
888888
var result = command.Parse("command");
889889

890890
result.FindResultFor(option)
891-
.Token
891+
.IdentifierToken
892892
.Should()
893893
.BeEquivalentTo(default(Token));
894894
}

src/System.CommandLine.Tests/ParsingValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public void A_custom_validator_can_be_added_to_an_option()
369369
{
370370
var value = r.GetValueOrDefault<int>();
371371

372-
r.AddError($"Option {r.Token.Value} cannot be set to {value}");
372+
r.AddError($"Option {r.IdentifierToken.Value} cannot be set to {value}");
373373
});
374374

375375
var command = new RootCommand { option };

src/System.CommandLine/Help/VersionOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void AddValidators()
4444
parent.Children.Where(r => !(r is OptionResult optionResult && optionResult.Option is VersionOption))
4545
.Any(IsNotImplicit))
4646
{
47-
result.AddError(LocalizationResources.VersionOptionCannotBeCombinedWithOtherArguments(result.Token?.Value ?? result.Option.Name));
47+
result.AddError(LocalizationResources.VersionOptionCannotBeCombinedWithOtherArguments(result.IdentifierToken?.Value ?? result.Option.Name));
4848
}
4949
});
5050
}

src/System.CommandLine/LocalizationResources.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static string InvalidCharactersInFileName(char invalidChar) =>
5454
/// </summary>
5555
internal static string RequiredArgumentMissing(ArgumentResult argumentResult) =>
5656
argumentResult.Parent is CommandResult commandResult
57-
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, commandResult.Token.Value)
57+
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, commandResult.IdentifierToken.Value)
5858
: RequiredArgumentMissing((OptionResult)argumentResult.Parent!);
5959

6060
/// <summary>
@@ -252,6 +252,6 @@ private static string GetResourceString(string resourceString, params object[] f
252252
return resourceString;
253253
}
254254

255-
private static string GetOptionName(OptionResult optionResult) => optionResult.Token?.Value ?? optionResult.Option.Name;
255+
private static string GetOptionName(OptionResult optionResult) => optionResult.IdentifierToken?.Value ?? optionResult.Option.Name;
256256
}
257257
}

src/System.CommandLine/Parsing/CommandResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal CommandResult(
2020
base(symbolResultTree, parent)
2121
{
2222
Command = command ?? throw new ArgumentNullException(nameof(command));
23-
Token = token ?? throw new ArgumentNullException(nameof(token));
23+
IdentifierToken = token ?? throw new ArgumentNullException(nameof(token));
2424
}
2525

2626
/// <summary>
@@ -31,15 +31,15 @@ internal CommandResult(
3131
/// <summary>
3232
/// The token that was parsed to specify the command.
3333
/// </summary>
34-
public Token Token { get; }
34+
public Token IdentifierToken { get; }
3535

3636
/// <summary>
3737
/// Child symbol results in the parse tree.
3838
/// </summary>
3939
public IEnumerable<SymbolResult> Children => SymbolResultTree.GetChildren(this);
4040

4141
/// <inheritdoc/>
42-
public override string ToString() => $"{nameof(CommandResult)}: {Token.Value} {string.Join(" ", Tokens.Select(t => t.Value))}";
42+
public override string ToString() => $"{nameof(CommandResult)}: {IdentifierToken.Value} {string.Join(" ", Tokens.Select(t => t.Value))}";
4343

4444
internal override bool UseDefaultValueFor(ArgumentResult argumentResult)
4545
=> argumentResult.Argument.HasDefaultValue && argumentResult.Tokens.Count == 0;

src/System.CommandLine/Parsing/OptionResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal OptionResult(
2222
base(symbolResultTree, parent)
2323
{
2424
Option = option ?? throw new ArgumentNullException(nameof(option));
25-
Token = token;
25+
IdentifierToken = token;
2626
}
2727

2828
/// <summary>
@@ -34,15 +34,15 @@ internal OptionResult(
3434
/// Indicates whether the result was created implicitly and not due to the option being specified on the command line.
3535
/// </summary>
3636
/// <remarks>Implicit results commonly result from options having a default value.</remarks>
37-
public bool IsImplicit => Token is null || Token.IsImplicit;
37+
public bool IsImplicit => IdentifierToken is null || IdentifierToken.IsImplicit;
3838

3939
/// <summary>
4040
/// The token that was parsed to specify the option.
4141
/// </summary>
42-
public Token? Token { get; }
42+
public Token? IdentifierToken { get; }
4343

4444
/// <inheritdoc/>
45-
public override string ToString() => $"{nameof(OptionResult)}: {Token?.Value ?? Option.Name} {string.Join(" ", Tokens.Select(t => t.Value))}";
45+
public override string ToString() => $"{nameof(OptionResult)}: {IdentifierToken?.Value ?? Option.Name} {string.Join(" ", Tokens.Select(t => t.Value))}";
4646

4747
/// <summary>
4848
/// Gets the parsed value or the default value for <see cref="Option"/>.

src/System.CommandLine/Parsing/ParseResultExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ private static void Diagram(
128128

129129
if (optionResult is not null)
130130
{
131-
builder.Append(optionResult.Token?.Value ?? optionResult.Option.Name);
131+
builder.Append(optionResult.IdentifierToken?.Value ?? optionResult.Option.Name);
132132
}
133133
else
134134
{
135-
builder.Append(((CommandResult)symbolResult).Token.Value);
135+
builder.Append(((CommandResult)symbolResult).IdentifierToken.Value);
136136
}
137137

138138

0 commit comments

Comments
 (0)