-
Notifications
You must be signed in to change notification settings - Fork 401
SymbolResults improvements #2024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if (optionResult.Children.Count == 0) | |
{ | |
if (optionResult.Option.Argument is { HasCustomParser: true }) | |
{ | |
if (optionResult.Option is { } opt) | |
{ | |
var argResult = optionResult.GetOrCreateDefaultArgumentResult(opt.Argument); | |
optionResult.AddChild(argResult); | |
ValidateAndConvertArgumentResult(argResult); | |
} | |
} | |
} |
{ | ||
return; | ||
} | ||
OptionResult optionResult = (OptionResult)_symbolResults[argumentNode.ParentOptionNode.Option]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is guaranteed to work, there can be no parsed OptionArgumentNode
without option being parsed and handled first
.Should() | ||
.Be(command); | ||
.BeAssignableTo<CommandResult>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use BeOfType
here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.Tokens
and 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.