fclp / fluent-command-line-parser

A simple, strongly typed .NET C# command line parser library using a fluent easy to use interface
Other
530 stars 85 forks source link

HelpCalled and HasErrors preserve values when Parse(args) is called multiple times #96

Open agracio opened 6 years ago

agracio commented 6 years ago

In an app that uses fluent-command-line-parser continuously var result = Parse(args) sets result.HelpCalled to true when help is called and stays true for all sub-sequential command calls.

Edit: result.HasErrors behaves similarly by setting value to false when one successful command is called. All incorrect commands after that will still have result.HasErrors set to false. Using version 1.5.0.20

siywilliams commented 6 years ago

Hi @agracio ,

Yes the internals of fclp remember some state from the last parse operation. It would be safer to recreate the fclp for each subsequent call at this stage until it can be changed to be state-less.

agracio commented 6 years ago

I have considered this approach as a workaround, but my app has complex setup stage and recreating it can add overhead to command parsing times, is there a way reset state? I am already forced to use reflection for some features so adding one more internal call cannot hurt :)

agracio commented 6 years ago

I think I solved the problem by re-initialising ParseEngine property before each call.

parser.ParseEngine = new CommandLineParserEngineMark2(new SpecialCharacters());

Is that enough to reset internal state?

siywilliams commented 6 years ago

I think the Help property will need to be reset also

agracio commented 6 years ago

So far my tests show that both HelpCalled and HasErrors are reset between multiple invocations of Parse(args) method. I will update this thread if I encounter other issues.