Support for named arguments?
Closed this issue · 1 comments
davidkeaveny commented
Am I right in thinking that Oakton (v6.1 currently) only supports positional arguments? If so, is there any plan to support named arguments?
For example, if I define my command as:
public class CreatePayrollInput
{
[Description("The number of items to create", Name = "number-of-items")]
public int NumberOfItems { get; set; }
[Description("The access group to use", Name = "access-group-id")]
public string AccessGroupId { get; set; }
[Description("The URL of the API", Name = "url")]
public Uri ApiUrl { get; set; }
[Description("The API bearer token to use with the API", Name = "token")]
public string ApiToken { get; set; }
}
[Description("Create a payroll", Name = "create-payroll")]
public class CreatePayrollInputCommand : OaktonCommand<CreatePayrollInput>
{
public override bool Execute(CreatePayrollInput input)
{
AnsiConsole.WriteLine($"Creating {input.NumberOfItems} items with access group {input.AccessGroupId}");
return true;
}
}
I would like to be able to execute it as dotnet run -- create-payroll --number-of-items 500 --access-group-id ABC --token XYZ --url http://localhost:4092/api
, rather than dotnet run -- create-payroll 500 ABC XYZ http://localhost:4092/api
which, while being succinct, is not so easy to read, especially should I want to add more arguments later on.
jeremydmiller commented
You can already use optional flags for exactly the syntax you described. That's all doc'd here:
https://jasperfx.github.io/oakton/guide/parsing.html#optional-flags