/// <summary> /// Handles <paramref name="result"/>. If parsing was successful, calls <see cref="IParseResult.InvokeAsync"/>. /// If parsing failed, any errors are written using <see cref="MsgFormatter"/>. /// </summary> /// <param name="result">The result to handle.</param> /// <param name="alwaysWriteHelpOnError">Always writes help when there is an error. If false, only writes help if an Error was <see cref="ErrorCode.HelpRequested"/>.</param> public async Task HandleAsync(IParseResult result, bool alwaysWriteHelpOnError = true) { if (result.Ok) { await result.InvokeAsync(); } else { if (result.Errors.Count > 0) { MsgFormatter.WriteErrors(Console, result.Errors); } if (alwaysWriteHelpOnError || result.Errors.Any(x => x.ErrorCode == ErrorCode.HelpRequested)) { if (result.Verb != null) { result.Verb.WriteSpecificHelp(Console, MsgFormatter); } else { MsgFormatter.WriteOverallHelp(Console, Verbs, Config); } } } }