I have to parse an imposed command line which mix single/double dash args, args with =
or
as separator,etc (not very proper....)
The command line is like myexe.exe -Url=https://blabla.com/ --TestValue=val1 -monoapp -Ctx "default ctx" Open -Test2=CO0ZJP6f-ca
I'm trying to do that with commandlineparser. (I suppose it's able to manage that, right ? )
So first I'm trying to parse the first parameter (myexe.exe -Url=https://blabla.com/
).
public class CommandLineOptions
{
[Option("Url", Required = true)]
public string Url { get; set; }
}
....... In another file but in the same assembly
static void Main(string[] args) // args[0] = "-Url=https://blabla.com/"
{
var commandLineOptions = new CommandLineOptions();
var parseResult = Parser.Default.ParseArguments<CommandLineOptions>(args).WithParsed(result => commandLineOptions = result);
System.Console.WriteLine(parseResult.Tag); //NotParsed
System.Console.WriteLine(commandLineOptions.Url);
}
With that code, I have 2 errors CommandLine.MissingRequiredOptionError
and CommandLine.UnknownOptionError
.
(The MissingRequiredOptionError
is produced beacause it cannot find the Url parameter)
So do you know where is my mistake ?
Thanks in advance for your help ;)