commandline icon indicating copy to clipboard operation
commandline copied to clipboard

UnParse does not match Parse - FormatCommandLine extension ignores Required

Open StefanBertels opened this issue 9 years ago • 0 comments

Thanks for the great lib.

I have an option class like this:

public class TargetArguments
{
    [Option('m', Required = true, HelpText = "might be an empty string?")]
    public string TargetCallMode { get; set; }

    public override string ToString() => Parser.Default.FormatCommandLine(this);
}

When my property is set to an empty string (zero length) I get no error when calling FormatCommandLine and there is no "-m" in output.

I suggest that FormatCommandLine throws an Exception if it would produce output that cannot be parsed later. UnParse should match Parse here.

Another question: Should an empty string cause the option to be missing? I would expect an zero length string to be a valid option value (it's more clear that null can be seen as missing). I guess this might be difficult to parse? Anyway: how to pass an empty string value? Something like -m ""

StefanBertels avatar Dec 01 '16 17:12 StefanBertels