Skip to content

[Question] UnrecognizedCommandParsingException Help Txt #601

@JunFWu

Description

@JunFWu

source code
McMaster.Extensions.CommandLineUtils CommandLineProcessor

   private bool ProcessUnexpectedArg(string argTypeName, string? argValue = null)
   {
       switch (_currentCommand.UnrecognizedArgumentHandling)
       {
           case UnrecognizedArgumentHandling.Throw:
               _currentCommand.ShowHint();
               var value = argValue ?? _enumerator.Current?.Raw;

               var suggestions = Enumerable.Empty<string>();

               if (_currentCommand.MakeSuggestionsInErrorMessage && !string.IsNullOrEmpty(value))
               {
                   suggestions = SuggestionCreator.GetTopSuggestions(_currentCommand, value);
               }

               throw new UnrecognizedCommandParsingException(_currentCommand, suggestions,
                   $"Unrecognized {argTypeName} '{value}'");

           case UnrecognizedArgumentHandling.CollectAndContinue:
               var arg = _enumerator.Current;
               if (arg != null)
               {
                   _currentCommand._remainingArguments.Add(arg.Raw);
               }
               return true;

           case UnrecognizedArgumentHandling.StopParsingAndCollect:
               // All remaining arguments are stored for further use
               AddRemainingArgumentValues();
               return false;
           default:
               throw new NotImplementedException();
       }
   }

when throw UnrecognizedCommandParsingException,this write Specify {flag} for a list of available options and commands.

come from _currentCommand.ShowHint();

What can I do to avoid the_currentCommand.ShowHint(); output while still throwing the 'UnrecognizedCommandParsingException' error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions