diff --git a/Src/CommandLine.cs b/Src/CommandLine.cs index a28566f..4d01d82 100644 --- a/Src/CommandLine.cs +++ b/Src/CommandLine.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using System.Reflection; using RT.Internal; using RT.PostBuild; @@ -1395,11 +1395,27 @@ public CommandLineParseException(ConsoleColoredString message, Func public virtual void WriteUsageInfoToConsole() { - ConsoleUtil.Write(GenerateHelp(ConsoleUtil.WrapToWidth())); + ConsoleUtil.Write(GetUsageInfo()); + } - Console.WriteLine(); - ConsoleUtil.Write(GenerateErrorText(ConsoleUtil.WrapToWidth())); + /// + /// Generates and returns usage information, followed by an error message describing to the user what it was that the + /// parser didn't understand. + public ConsoleColoredString GetUsageInfo() + { + var s = GenerateHelp(ConsoleUtil.WrapToWidth()); + if (WriteErrorText) + s += Environment.NewLine + GenerateErrorText(ConsoleUtil.WrapToWidth()); + return s; } + + /// + /// Determines whether and should call and output it to the console. Default is true. + /// + /// Only set this to false if the user explicitly asked to see the help screen. Otherwise its appearance + /// without explanation is confusing. + protected internal virtual bool WriteErrorText => true; } /// Indicates that the user supplied one of the standard options we recognize as a help request. @@ -1409,6 +1425,8 @@ public sealed class CommandLineHelpRequestedException(FuncPrints usage information. public override void WriteUsageInfoToConsole() => ConsoleUtil.Write(GenerateHelp(ConsoleUtil.WrapToWidth())); + /// + protected internal override bool WriteErrorText => false; } /// Specifies that the arguments specified by the user on the command-line do not pass the custom validation checks.