-
-
Notifications
You must be signed in to change notification settings - Fork 736
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
Implementation of ValidateAndGetBestMatch #1700
Implementation of ValidateAndGetBestMatch #1700
Conversation
This function will validate all commands from a SearchResult and return the result of said validation, along with the command matched, if a valid match was found.
Going to cc @Cenngo on this just for sanity |
public async Task<(IResult, Optional<CommandMatch>)> ValidateAndGetBestMatch(SearchResult matches, ICommandContext context, IServiceProvider provider, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) | ||
{ | ||
if (!matches.IsSuccess) | ||
return (matches, Optional.Create<CommandMatch>()); |
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 dont think returning an optional CommandMatch to indicate to the user that their SearchResult wasnt successful isnt the most user friendly way of validating a command search. Instead of returning a Tuple, i think you should encapsulate this in an IResult
that way you can provide more information to the user and it would be easier to build a command execution pipeline around this, since your goal is to allow people to utilize this.
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 see.
//Since ValidateAndGetBestMatch is deterministic on the return type, we can use pattern matching on the type for infering the code flow. | ||
var (validationResult, commandMatch) = await ValidateAndGetBestMatch(searchResult, context, services, multiMatchHandling); | ||
|
||
if(validationResult is SearchResult) |
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.
Tho i understand the way you are using this workflow to branch out the execution method, i dont think it is the most descript way of doing this. I think this should be more user readable to make it easier to maintain. Using an IResult
to return the method result, with some additional info for branching out the pipeline, might be a better idea.
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.
Understood.
Other than that, it all seems good. |
@roridev Are you able to make the requested changes? |
Im able now, just give me a moment |
Changes: - Use IResult instead of Optional CommandMatch - Rework branching workflow
Please check if the changes done align with what was requested. Fun things that were discovered while doing this:
|
@Cenngo waiting on your final approval |
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.
The changes you made address the issues i mentioned. Great to hear that this also led you to fixing a problem.
return validationResult; | ||
} | ||
|
||
private async Task<IResult> handleCommandPipeline(MatchResult matchResult, ICommandContext context, IServiceProvider services) |
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.
Could you please make this pascal casing?
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.
oh sure rider autocorrected it to that.
As discussed on #1699 this pr comes with a rewrite of the logic on
CommandService#ExecuteAsync
, splitting it into two functions.ExecuteAsync
- will continue to do theSearch-Verify-Match-Execute
loop as it did before.ValidateAndGetBestMatch
- Verifies from a set of commands (SearchResult
) with the specifiedICommandContext
,IServiceProvider
andMultiMatchHandling
which command is the optimal one, using the previously established classification and ranking systems.Breaking Changes
None.
Focus
Code cleanup and creation of an new public api.