I have begun starting using this https://github.com/commandlineparser/commandline to pass the input parameters parsed to my application.
My problem here is that the input parameter passed is not required, meaning you can start the application without speciying them.
I have so far defined my command line options as such
public class CommandLineOptions
{
[Option(longName: "client-id", Required = false, HelpText = "Id of the client")]
public string ClientId { get; set; }
[Option(longName: "pw", Required = false, HelpText = "pw.")]
public string Password{ get; set; }
}
and in my main I parse them like this
Access access= Parser.Default.ParseArguments<CommandLineOptions>(args)
.MapResult(parsedFunc: (CommandLineOptions opts) => new Access(opts.ClientId, opts.Password),
notParsedFunc: (IEnumerable<Error> a) => new Access());
I want to use the parsedfunc:
in case it is specified, and notParsedFunc:
in case it is not specified.
but this always triggers the parsedFunc
and since the value of both parameters are null
, my inner method fails?
I've also tried changing the option to not required, this then throws an error in the console window that these parameter has not been specified, but triggers the correct method.