-
Notifications
You must be signed in to change notification settings - Fork 88
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
Chaining AddCommand #78
base: master
Are you sure you want to change the base?
Conversation
Fair warning - this is a suggestion, and not really production worthy. If you have any pointers on how this could be achieved, or would like to add it to the backlog, or decline it from happening - that is fine :) |
Okay, I got it working using an extension method:
So now this compiles and is confirming to work:
So maybe just ignore it, or add the extension method perhaps somewhere? Maybe it just me anyways, and it was quite ezy to write anyways |
Sorry for the late reply. Thank you for your proposal.👍 I did not introduce a chain (Fluent API) for AddCommand because it is based on ASP.NET Core's Minimal APIs. In ASP.NET Core, the example is as follows: app.MapGet("/hello", () => "Hello!").AllowAnonymous().WithName("Hello");
app.MapGet("/bye", () => "Bye!").RequireAuthorization().WithName("Bye"); app.MapGet("/hello", () => "Hello!")
.AllowAnonymous()
.WithName("Hello")
.MapGet("/bye", () => "Bye!")
.RequireAuthorization()
.WithName("Bye");
app.MapGet("/foo", () => "Foo").MapGet("/bar", () => "bar"); I feel this is a bit confusing with the mapping of endpoints and their configuration mixed in. If Cocona had an API where AddCommand itself takes a delegate for configuration, the chain can be naturally applied. app.AddCommand("set-config", () => { ... }, options => options.Alias("sc"))
.AddCommand("get-config", () => { ... }, options => options.Alias("gc")); I am also concerned that the API may look to allow sub-commands to be added to the command. |
Maybe this is possible but I just could not figure out how. But the structure I have in my real program is this:
And I would like to have it chained: (because it looks good)
It would be pretty cool that have it like that. But it looked not that easy to change so I did an alternate version using a new functions name AddCommands that takes an array of commands, and I made an extension method to cast it to CoconaApp so the run function could be called.
Quite ugly, and I only wrote two tests.
Do not have the time right now to do something better, so maybe take this as an suggestion rather than something actually good.