Skip to content
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

Increase the number of verbs supported #914

Open
unwobbling opened this issue Feb 15, 2024 · 3 comments
Open

Increase the number of verbs supported #914

unwobbling opened this issue Feb 15, 2024 · 3 comments

Comments

@unwobbling
Copy link

Would it be a possible to remove the limit on the number of verbs supported?

Currently the limit is 16.

Ideal would be no limit if that's not possible due to the implementation 32 would be great.

In:

ParserExtensions
.ParseArguments<>

ParserResultExtensions
.MapResult()

@quotschmacher
Copy link

I just searched for this topic at Stackoverflow and unlimited / dynamic number is not possible.

But I would like to have more than 16 parameters, too. 32 would be really nice.

@Roiskia
Copy link

Roiskia commented Mar 3, 2024

This is already possible. I stumpled upon this while trying to use dependency injection with commandlineparser. I dont think that there is a real limit on the number of verbs by doing it this way:

using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var services = new ServiceCollection()
.AddTransient<IController<FooOptions>, FooController>()
// ...
.AddTransient<IController<FooOptions17>, FooController17>()
.BuildServiceProvider();

Type[] optionTypes = [
    typeof(FooOptions),
// ...
    typeof(FooOptions17),
];

Parser.Default.ParseArguments(args, optionTypes)
.MapResult((IOptions o) => {
    Type t = typeof(IController<>).MakeGenericType(o.GetType());
    var controller = services.GetRequiredService(t);
    return t.GetMethod(nameof(IController<IOptions>.Run))?.Invoke(controller, [o]);
},
errs => 1);

@tforve
Copy link

tforve commented Sep 11, 2024

The way we managed to get arround the limitation was to get the parserResult.Value as a specific type. This worked because all of our verbs are inherit from the same baseclass.
Examplecode:

ParserResult<object> parserResult = parser.ParseArguments(args, LoadVerbs());

ExampleBaseClass value = parserResult.Value as ExampleBaseClass;
if (value == null)
{
    ErrorCase(parserResult);
}
 result = value.Execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants