Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/System.CommandLine.Tests/ArgumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void Option_ArgumentResult_parentage_to_root_symbol_is_set_correctly_when
.Parent
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Command
.Should()
Expand Down Expand Up @@ -340,7 +340,7 @@ public void Command_ArgumentResult_Parent_is_set_correctly_when_token_is_implici
argumentResult
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Command
.Should()
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Outer_command_is_identified_correctly_by_Parent_property()
.CommandResult
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Command
.Name
Expand Down
6 changes: 3 additions & 3 deletions src/System.CommandLine.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void When_options_with_the_same_name_are_defined_on_parent_and_child_comm
result.CommandResult
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Children
.Should()
Expand Down Expand Up @@ -697,7 +697,7 @@ public void When_options_with_the_same_name_are_defined_on_parent_and_child_comm
result.CommandResult
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Children
.Should()
Expand Down Expand Up @@ -1008,7 +1008,7 @@ public void Option_and_Command_can_have_the_same_alias()
.CommandResult
.Parent
.Should()
.BeAssignableTo<CommandResult>()
.BeOfType<CommandResult>()
.Which
.Children
.Should()
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private protected override string DefaultName
/// <returns>Returns the default value for the argument, if defined. Null otherwise.</returns>
public object? GetDefaultValue()
{
return GetDefaultValue(new ArgumentResult(this, null));
return GetDefaultValue(new ArgumentResult(this, null!, null));
}

internal abstract object? GetDefaultValue(ArgumentResult argumentResult);
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/ParseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace System.CommandLine
public class ParseResult
{
private readonly IReadOnlyList<ParseError> _errors;
private readonly RootCommandResult _rootCommandResult;
private readonly CommandResult _rootCommandResult;
private readonly IReadOnlyList<Token> _unmatchedTokens;
private Dictionary<string, IReadOnlyList<string>>? _directives;
private CompletionContext? _completionContext;

internal ParseResult(
Parser parser,
RootCommandResult rootCommandResult,
CommandResult rootCommandResult,
CommandResult commandResult,
Dictionary<string, IReadOnlyList<string>>? directives,
List<Token> tokens,
Expand Down
5 changes: 3 additions & 2 deletions src/System.CommandLine/Parsing/ArgumentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ArgumentResult : SymbolResult

internal ArgumentResult(
Argument argument,
SymbolResult? parent) : base(parent)
SymbolResultTree symbolResultTree,
SymbolResult? parent) : base(symbolResultTree, parent)
{
Argument = argument ?? throw new ArgumentNullException(nameof(argument));
}
Expand Down Expand Up @@ -110,7 +111,7 @@ Parent is { } &&

if (Parent!.UseDefaultValueFor(argument))
{
var argumentResult = new ArgumentResult(argument, Parent);
var argumentResult = new ArgumentResult(argument, SymbolResultTree, Parent);

var defaultValue = argument.GetDefaultValue(argumentResult);

Expand Down
7 changes: 4 additions & 3 deletions src/System.CommandLine/Parsing/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ namespace System.CommandLine.Parsing
/// <summary>
/// A result produced when parsing a <see cref="Command" />.
/// </summary>
public class CommandResult : SymbolResult
public sealed class CommandResult : SymbolResult
{
internal CommandResult(
Command command,
Token token,
SymbolResultTree symbolResultTree,
CommandResult? parent = null) :
base(parent)
base(symbolResultTree, parent)
{
Command = command ?? throw new ArgumentNullException(nameof(command));
Token = token ?? throw new ArgumentNullException(nameof(token));
Expand All @@ -33,7 +34,7 @@ internal CommandResult(
/// <summary>
/// Child symbol results in the parse tree.
/// </summary>
public IEnumerable<SymbolResult> Children => GetChildren(this);
public IEnumerable<SymbolResult> Children => SymbolResultTree.GetChildren(this);

internal sealed override int MaximumArgumentCapacity
{
Expand Down
3 changes: 2 additions & 1 deletion src/System.CommandLine/Parsing/OptionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public sealed class OptionResult : SymbolResult

internal OptionResult(
Option option,
SymbolResultTree symbolResultTree,
Token? token = null,
CommandResult? parent = null) :
base(parent)
base(symbolResultTree, parent)
{
Option = option ?? throw new ArgumentNullException(nameof(option));
Token = token;
Expand Down
6 changes: 6 additions & 0 deletions src/System.CommandLine/Parsing/ParseOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ private void ParseCommandArguments(CommandNode commandNode, ref int currentArgum

if (currentArgumentCount < argument.Arity.MaximumNumberOfValues)
{
if (CurrentToken.Symbol is null)
{
// update the token with missing information now, so later stages don't need to modify it
CurrentToken.Symbol = argument;
}

var argumentNode = new CommandArgumentNode(
CurrentToken,
argument,
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Parsing/ParseResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void Diagram(
builder.Append("[ ");
builder.Append(symbolResult.Token().Value);

foreach (SymbolResult child in symbolResult.GetChildren(symbolResult))
foreach (SymbolResult child in symbolResult.SymbolResultTree.GetChildren(symbolResult))
{
if (child is ArgumentResult arg &&
(arg.Argument.ValueType == typeof(bool) ||
Expand Down
Loading