Skip to content

Commit a261f42

Browse files
committed
Add and allow custom help text
1 parent 5011331 commit a261f42

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

SabreTools.CommandLine/CommandSet.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public class CommandSet
4242

4343
#region Properties
4444

45+
/// <summary>
46+
/// Custom help text to print instead of the automatically
47+
/// generated generic help
48+
/// </summary>
49+
/// <remarks>
50+
/// This only replaces the automatically generated help
51+
/// for <see cref="OutputGenericHelp"/>. It does not impact
52+
/// either <see cref="OutputAllHelp"/> or <see cref="OutputFeatureHelp"/>.
53+
/// </remarks>
54+
public string? CustomHelp { get; set; }
55+
4556
/// <summary>
4657
/// Feature that represents the default functionality
4758
/// for a command set
@@ -777,24 +788,34 @@ public void OutputGenericHelp(bool detailed = false)
777788
if (_header.Count > 0)
778789
output.AddRange(_header);
779790

780-
// Now append all available top-level flags
781-
output.Add("Available options:");
782-
foreach (var input in _inputs.Values)
791+
// If custom help text is defined
792+
if (CustomHelp != null)
783793
{
784-
var outputs = input.Format(pre: 2, midpoint: 30, detailed);
785-
if (outputs != null)
786-
output.AddRange(outputs);
794+
CustomHelp = CustomHelp.Replace("\r\n", "\n");
795+
string[] customLines = CustomHelp.Split("\n");
796+
output.AddRange(customLines);
787797
}
788-
789-
// If there is a default feature
790-
if (DefaultFeature != null)
798+
else
791799
{
792-
foreach (var input in DefaultFeature.Children)
800+
// Append all available top-level flags
801+
output.Add("Available options:");
802+
foreach (var input in _inputs.Values)
793803
{
794-
var outputs = input.Value.Format(pre: 2, midpoint: 30, detailed);
804+
var outputs = input.Format(pre: 2, midpoint: 30, detailed);
795805
if (outputs != null)
796806
output.AddRange(outputs);
797807
}
808+
809+
// If there is a default feature
810+
if (DefaultFeature != null)
811+
{
812+
foreach (var input in DefaultFeature.Children)
813+
{
814+
var outputs = input.Value.Format(pre: 2, midpoint: 30, detailed);
815+
if (outputs != null)
816+
output.AddRange(outputs);
817+
}
818+
}
798819
}
799820

800821
// Append the footer, if needed
@@ -818,7 +839,7 @@ public void OutputAllHelp(bool detailed = false)
818839
if (_header.Count > 0)
819840
output.AddRange(_header);
820841

821-
// Now append all available flags recursively
842+
// Append all available flags recursively
822843
output.Add("Available options:");
823844
foreach (var input in _inputs.Values)
824845
{

0 commit comments

Comments
 (0)