Skip to content

Conversation

@jonsequitur
Copy link
Contributor

These changes attempt to improve the clarity of the SetHandler methods by removing the params parameters and replacing them with a number of IValueDescriptor<T> parameters matching the number of generic type arguments.

Since DI-like behaviors are fairly non-obvious, I'll likely also experiment here with removing the internal service provider and see if BinderBase<T> can fulfill its role.


var command = new Command("hello");
command.SetHandler((InvocationContext ctx) =>
command.SetHandler(ctx =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's really nice for the simple handlers to be naturally-typed here (and in the other 1000 callsites in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Settling on InvocationContext for the case where we do this (i.e. removing support for ParseResult, etc. as parameters) reduces a lot of DI-ish complexity in these handlers. If we pull this thread hard enough, the need for the service provider might disappear.

Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major, but man those simple callsites look a lot nicer.

@jonsequitur jonsequitur requested a review from adamsitnik May 5, 2022 13:46
Copy link
Member

@Keboo Keboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Might be worth reviewing System.CommandLine.Generator after this merges, as I suspect it could be cleaned up a little bit to leverage the InvocationContext SetHandler overload.

{
var valueSource = ValueDescriptorDefaultValueSource.Instance;

valueSource.TryGetValue(valueDescriptor, context, out var value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I dislike var here as it is not clear what the type of value is.

{
var valueSource = ValueDescriptorDefaultValueSource.Instance;

valueSource.TryGetValue(valueDescriptor, context, out var value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we care about the case where TryGetValue returns false? Should there be something line BoundValue.None to return in that case?

@jonsequitur jonsequitur marked this pull request as ready for review May 7, 2022 17:14
@jonsequitur jonsequitur merged commit 55dbf39 into dotnet:main May 7, 2022
@jonsequitur jonsequitur deleted the SetHandler-improvements branch June 17, 2022 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants