1- using System . Diagnostics ;
1+ using System . Diagnostics ;
22using System . Reflection ;
33using RT . Internal ;
44using RT . PostBuild ;
@@ -1395,11 +1395,27 @@ public CommandLineParseException(ConsoleColoredString message, Func<int, Console
13951395 /// understand.</summary>
13961396 public virtual void WriteUsageInfoToConsole ( )
13971397 {
1398- ConsoleUtil . Write ( GenerateHelp ( ConsoleUtil . WrapToWidth ( ) ) ) ;
1398+ ConsoleUtil . Write ( GetUsageInfo ( ) ) ;
1399+ }
13991400
1400- Console . WriteLine ( ) ;
1401- ConsoleUtil . Write ( GenerateErrorText ( ConsoleUtil . WrapToWidth ( ) ) ) ;
1401+ /// <summary>
1402+ /// Generates and returns usage information, followed by an error message describing to the user what it was that the
1403+ /// parser didn't understand.</summary>
1404+ public ConsoleColoredString GetUsageInfo ( )
1405+ {
1406+ var s = GenerateHelp ( ConsoleUtil . WrapToWidth ( ) ) ;
1407+ if ( WriteErrorText )
1408+ s += Environment . NewLine + GenerateErrorText ( ConsoleUtil . WrapToWidth ( ) ) ;
1409+ return s ;
14021410 }
1411+
1412+ /// <summary>
1413+ /// Determines whether <see cref="WriteUsageInfoToConsole"/> and <see cref="GetUsageInfo"/> should call <see
1414+ /// cref="GenerateErrorText"/> and output it to the console. Default is <c>true</c>.</summary>
1415+ /// <remarks>
1416+ /// Only set this to <c>false</c> if the user explicitly asked to see the help screen. Otherwise its appearance
1417+ /// without explanation is confusing.</remarks>
1418+ protected internal virtual bool WriteErrorText => true ;
14031419}
14041420
14051421/// <summary>Indicates that the user supplied one of the standard options we recognize as a help request.</summary>
@@ -1409,6 +1425,8 @@ public sealed class CommandLineHelpRequestedException(Func<int, ConsoleColoredSt
14091425{
14101426 /// <summary>Prints usage information.</summary>
14111427 public override void WriteUsageInfoToConsole ( ) => ConsoleUtil . Write ( GenerateHelp ( ConsoleUtil . WrapToWidth ( ) ) ) ;
1428+ /// <inheritdoc/>
1429+ protected internal override bool WriteErrorText => false ;
14121430}
14131431
14141432/// <summary>Specifies that the arguments specified by the user on the command-line do not pass the custom validation checks.</summary>
0 commit comments