Cannot parse "1"
See original GitHub issueE.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
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Why I cannot parse "+1" to int? [duplicate]
I am trying to parse +1 value to an int value. In my code +1 is a String and i am trying to...
Read more >Black cannot parse multiple unpacking operations in one line
Describe the bug Black cannot parse an expression with multiple unpacking operations on one line that executes fine with Python.
Read more >Android Question Exception: Cannot parse: -1 as boolean
I port a working code from VB to B4A. When data in Bluetooth communication, I received "Exception: Cannot parse: -1 as boolean" error...
Read more >Re: cannot parse the file - SOLVED - Adobe Support Community
My party trick is to drag the recalcitrant file into a hex editor and look at the header because every format has its...
Read more >How to resolve the error: "Message Cannot parse null string"
The error I am getting is: HTTP Status 500 – Internal Server Error Type Exception Report Message Cannot parse null string
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@elgonzo when I change LINE_NUMBER value from 1 KEEP_ALIVE_OPTION is also recognized This is for fiddle example
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.<strike>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…</strike> (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 😉