Command-line-api: Not possible to bind option with dash in its name to method parameter

Created on 4 Jun 2019  路  2Comments  路  Source: dotnet/command-line-api

The documentation for syntax-first method binding states that:

Parameters are matched using a naming convention that converts camel-cased parameters to kebab-cased options. In this example, the option --an-int matches parameter anInt on the DoSomething method.

However, it is not possible to have a command option named "--system-name" and bind it to a parameter string systemName

bug

All 2 comments

Adding some sample code the reproduces the issue:
```C#
var outer = new Command("outer");
outer.AddOption(new Option("--system-name", argument: new Argument()));

var inner = new Command("inner");
outer.AddCommand(inner);

inner.Handler = CommandHandler.Create((string systemName, ParseResult result) =>
{
string sName = result.RootCommandResult.ValueForOption("--system-name");
});

outer.Handler = CommandHandler.Create((string systemName, ParseResult result) =>
{

});
`` When invoked withouter.InvokeAsync("outer --system-name foo");thesystemNameparameter is appropriately passed. When invoking withouter.InvokeAsync("outer --system-name foo inner");thesystemNameis not passed, and you are forced to look it up from theParseResult`.

This is now fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erichiller picture erichiller  路  3Comments

rgueldenpfennig picture rgueldenpfennig  路  4Comments

oising picture oising  路  7Comments

jonsequitur picture jonsequitur  路  6Comments

jnm2 picture jnm2  路  6Comments