Conversation
…ecific property anyway
…rty to find children using symbol dictionary
|
|
||
| if (optionNode.Children is null) // no Arguments | ||
| { | ||
| if (optionResult.Option.Argument.HasCustomParser) |
There was a problem hiding this comment.
previously this logic was performed as part of the validation (ValidateAndConvertOptionResult). Since here we know that given OptionNode was parsed with no arguments, we can create the argument result now and let validation method just validate without performing mutations.
command-line-api/src/System.CommandLine/Parsing/ParseResultVisitor.cs
Lines 489 to 500 in 9c48247
| { | ||
| return; | ||
| } | ||
| OptionResult optionResult = (OptionResult)_symbolResults[argumentNode.ParentOptionNode.Option]; |
There was a problem hiding this comment.
this is guaranteed to work, there can be no parsed OptionArgumentNode without option being parsed and handled first
| .Symbol | ||
| .Should() | ||
| .Be(command); | ||
| .BeAssignableTo<CommandResult>() |
There was a problem hiding this comment.
I think you can use BeOfType here, no?
There was a problem hiding this comment.
iirc it's RootCommandResult here (which is internal)
edit:
[xUnit.net 00:00:00.93] System.CommandLine.Tests.ArgumentTests+CustomParsing.Command_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit [FAIL]
Failed System.CommandLine.Tests.ArgumentTests+CustomParsing.Command_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit [34 ms]
Error Message:
Expected type to be System.CommandLine.Parsing.CommandResult, but found System.CommandLine.Parsing.RootCommandResult.
Stack Trace:
at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
at FluentAssertions.Types.TypeAssertions.Be(Type expected, String because, Object[] becauseArgs)
at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeOfType(Type expectedType, String because, Object[] becauseArgs)
at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeOfType[T](String because, Object[] becauseArgs)
at System.CommandLine.Tests.ArgumentTests.CustomParsing.Command_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit() in D:\projects\command-line-api\src\System.CommandLine.Tests\ArgumentTests.cs:line 340
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
|
@jonsequitur thank you for the review! |
SymbolResults improvements based on feedback from our last meeting (notes):
I still need to implement a copy-free approach for
Symbol.Tokensand I don't like the fact that many of the SymbolResults properties/methods are virtual and just callingRoot.MethodAbc. I'll send another PR tomorrow or just update this one.