Unable to parse TimeSpan given from the FormatCommandLine
Qrtic opened this issue · 2 comments
It seems like starting from version 2.7 a bug in unparsing of TimeSpan options appeared.
Version 2.6 unparsing results in unquoted timespan value (i.e. 00:01:00), whereas version's 2.7 or 2.7.82 is quoted (i.e. "00:01:00"), which couldn't be parsed.
Was it intended to be quoted and it should be properly parsed then?
Here's a sample code, which describes an issue.
var args = Parser.Default.FormatCommandLine(new Options
{
Interval = TimeSpan.FromMinutes(1)
}).Split(' ');
// results in quoted TimeSpan: --interval "00:01:00"
// which throws on parsing with CommandLine.BadFormatConversionError
Parser.Default.ParseArguments<Options>(args)
.MapResult(
options => options,
errs => throw new Exception(errs.First().ToString()));
Hi, @Qrtic. First of all thank you for using this project and for taking time to open an issue.
You're right. There's a discrepancy on how the library parses and unparses System.TimeSpan value type. When parsing the value must be unquoted (see this unit test), but is formatted with quotes.
In local branch I wrote two new tests. Both to enforce the correct behaviour of parse/unparse unquoted. Obviously the unparse one fails and fixing it will solve your issue.
I'm working on it.
Just one note: if you pass to a program a quoted command line throgh the terminal, quotes are not passed to the library. Quotes persist if escaped or when passed directly to the parsing engine by code.
Great, good work, thanks a lot!