Cannot parse "1"
E.g. "--KEEP_ALIVE_OPTION=1".
This treats by the parser as no value: Option 'keep_alive_option" has no value. Required option 'keep_alive_option' is missing.
public class KeepAliveOptions
{
[Option(Required = true)]
public string KEEP_ALIVE_OPTION { get; set; }
[Option(Required = true)]
public string LOGIN_URL { get; set; }
[Option(Required = true)]
public string ADVISOR_PASSWORD { get; set; }
[Option(Required = true)]
public string COMPANY_NUMBER { get; set; }
[Option(Required = true)]
public string OUT_DIR { get; set; }
[Option(Required = true)]
public string UserID { get; set; }
[Option(Required = true)]
public string Password { get; set; }
}
public ParserResult<T> Parse<T>(string[] args) where T : IScriptOptions
{
Parser parser = new(s =>
{
s.CaseSensitive = false;
s.IgnoreUnknownArguments = true;
s.HelpWriter = Parser.Default.Settings.HelpWriter;
});
var scriptOptions = new List<string>();
for (int i = 0; i < args.Length; i++)
{
string option = $"--{args[i].TrimStart('/')}";
scriptOptions.Add(option);
}
return parser.ParseArguments<T>(scriptOptions);
}
var result = Parse<KeepAliveOptions>(args)
.WithParsed(keepAliveOptions => options = keepAliveOptions)
Tried to change KEEP_ALIVE_OPTION type to int, it doesn't change anything
Fiddle: https://dotnetfiddle.net/vbujQc
Cannot reproduce.
Both 2.9.0-preview (dotnetfiddle: https://dotnetfiddle.net/ziCfC9) as well as 2.8.0 (dotnetfiddle: https://dotnetfiddle.net/aWzTh2) work as expected, with the LINE_NUMBER property receiving the value 1.
@elgonzo reproduced (but not simply), added link to the body
@elgonzo when I change LINE_NUMBER value from 1 KEEP_ALIVE_OPTION is also recognized This is for fiddle example
var args = new string[] {"/SCRIPT_NAME=DEALER_TRACK_KEEP_ALIVE", "/OEM_FAMILY=GM", "/COMPLAINT_CODE=\"0131\"", "/OUT_DIR=C:\\\\Applications\\\\DataFiles\\\\", "/KEEP_ALIVE_OPTION=1", "/STORY=\"Lorem ipsum #UPDATE#dolor sit amet\"", "/DEALER_TRACK_LOGIN_URL=https://blah",
"/DEALER_TRACK_UserID=myId", "/DEALER_TRACK_Password=myPwd12", "/DEALER_TRACK_ADVISOR_PASSWORD=\"asd\"", "/DEALER_TRACK_COMPANY_NUMBER=\"TT\"", "/RO_NUMBER=3464990", "/LINE_NUMBER=1", "/CAUSAL_PART_NUMBER=\"11546959:SL-N-BOLT (00293-CKT)\""};
Ok, thank you
My apologies, i deleted my comment by accident. I cannot directly restore it, so i have to post it again. That unfortunately means, you get another email notification for basically the same comment of mine. Sorry about that :-)
Alright. The problem is not with the --KEEP_ALIVE_OPTION option itself. This is just an unfortunate aribtrary side effect happening after CommandlineParser went off the rails.
The actual cause of the problem are the many unknown options specified for the CLI invocation, and the actual bug is CommandlineParser not being able to cope with that many unknown options and completely losing its mind and going crazy. The particular order in which unknown and known options follow each other is probably also playing a role here, although i have not investigated in that direction any further... (EDIT: False conclusion, see my next comment below)
(By the way, in the concrete example you provided, it would just be enough to add the missing LINE_NUMBER option to DTLoginOptions class, and it kinda works: https://dotnetfiddle.net/P8O8dA Only "kinda" of course, because i think that this is just circumstantial behavior, and any other unknown option you add to the CLI invocation might make CommandlineParser lose its mind again ;-)
when I change LINE_NUMBER value from 1 KEEP_ALIVE_OPTION is also recognized This is for fiddle example
Ah, your observation made me remember. There was a similar or same issue reported already not that long ago: https://github.com/commandlineparser/commandline/issues/776