Closed opinionmachine closed 7 years ago
Actually - I had, as suspected missed the AdditionalOptionsFound list. Using that and the CaptureAdditionalArguments() callback with a flag I could achieve almost what I want. My only missing feature is "> exe.exe garblage" is not flagged as being garbage, but "> exe.exe --filepsth C:\Temp" and "> exe.exe --filepath C:\Temp garblage" are both correctly flagged as mistakes.
bool otherInvalidOccurrence = false;
commandLineParser.Setup(arguments => arguments.FilePath)
.As("FilePath")
.CaptureAdditionalArguments(a => otherInvalidOccurrence = true)
.WithDescription(" - FilePath. Should be wrapped in quotes");
if (result.AdditionalOptionsFound.Any() || otherInvalidOccurrence)
{
commandLineParser.HelpOption.ShowHelp(commandLineParser.Options);
return false; // not relevant to this, basically just not running the rest of the program.
}
If I have declared an optional parameter such as "filepath" and some user types "filepsth" - is there any way to show help if an unknown option is specified even though no required options are missing?
I see it as follows:
I have tried to find a way to handle situation 3 above. The UseForEmptyArgs() on SetupHelp does NOT address this. I need a way to capture what looks like a correctly parsable option is not a valid one (again --filepsth instead of --filepath)