Exemplo n.º 1
0
 /// <summary>
 /// Handles <paramref name="result"/>. If parsing was successful, calls <see cref="IParseResult.Invoke"/>.
 /// 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 void Handle(IParseResult result, bool alwaysWriteHelpOnError = true)
 {
     if (result.Ok)
     {
         result.Invoke();
     }
     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);
             }
         }
     }
 }