commandline
commandline copied to clipboard
Issue with Verb and First Value in 2.0.275-beta
Hi,
I may be doing this wrong, but it may also be a bug. When I create a verb the Value with index 0 that I get back is the verb, rather than the first Value. So to work around it I am having to create a dummy value just to allow the verb to be ignored. e.g.
[Verb("strip", HelpText = "Strip all messages.")]
public class StripOptions
{
[Value(0, Required = true)]
public string Dummy { get; set; }
[Value(1, Required = true)]
public string InputFile { get; set; }
[Option('o', "Output", HelpText = "The output file name, defaulted to input filename prefixed with 'stripped-'")
]
public string OutputFile { get; set; }
}
static int Main(string[] args)
{
return Parser.Default.ParseArguments<StripOptions>(args)
.MapResult(RunStripAndReturnExitCode,
errs => 1);
Without the 'Dummy' value with index 0, I just get 'strip' in InputFile.
This is with .net 4.5 on win7.
Ok I have some more info on this! The problem only occurs when there is only one command. If you register more it works fine without the need for the dummy field.
Hope that helps diagnose and fix. For now one can either create the dummy field (which is bad as it shows in the help) or have more than one command.
You can use method ParseArguments(IEnumerable<string> args, params Type[] types)
with just one type.
I think method ParseArguments<T>(IEnumerable<string> args)
is not supposed to be used with verbs. It's better if this methods throws exception when verb is given or it's logic is changed to support verbs.