in src/Cli/func/Actions/HelpAction.cs [274:343]
private static void DisplayOptions(IEnumerable<ICommandLineOption> options)
{
var longestName = options.Max(o =>
{
const int coloringChars = 2;
const int longNameSwitches = 2;
const int shortNameSwitches = 3;
const int shortNameSpace = 1;
if (o.HasLongName && o.HasShortName)
{
return o.LongName.Length + longNameSwitches + o.ShortName.Length + shortNameSwitches + shortNameSpace + coloringChars;
}
else if (o.HasLongName)
{
return o.LongName.Length + longNameSwitches + coloringChars;
}
else
{
return 0;
}
});
foreach (var option in options)
{
var stringBuilder = new StringBuilder();
if (option.HasLongName)
{
stringBuilder.Append($"--{option.LongName}");
}
if (option.HasShortName)
{
stringBuilder.Append($" [-{option.ShortName}]");
}
var helpSwitch = string.Format($" {{0, {-longestName}}} ", stringBuilder.ToString().DarkGray());
var helpSwitchLength = helpSwitch.Length - 2; // helpSwitch contains 2 formatting characters.
var helpText = option.Description;
if (string.IsNullOrWhiteSpace(helpText))
{
continue;
}
if (helpSwitchLength + helpText.Length < SafeConsole.BufferWidth || helpSwitchLength > SafeConsole.BufferWidth)
{
ColoredConsole.WriteLine($"{helpSwitch}{helpText}");
}
else
{
ColoredConsole.Write(helpSwitch);
var lineNumber = 1;
while (helpText.Length + helpSwitchLength > SafeConsole.BufferWidth)
{
var segment = helpText.Substring(0, SafeConsole.BufferWidth - helpSwitchLength - 1);
helpText = helpText.Substring(SafeConsole.BufferWidth - helpSwitchLength - 1);
if (lineNumber != 1)
{
segment = segment.PadLeft(helpSwitchLength + segment.Length);
}
ColoredConsole.WriteLine(segment);
lineNumber++;
}
if (helpText.Length > 0)
{
ColoredConsole.WriteLine(helpText.PadLeft(helpSwitchLength + helpText.Length, ' '));
}
}
}
}