Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,11 @@ public string GetHelpText(string commandName = null)

optionsBuilder.AppendLine();
optionsBuilder.AppendLine("Options:");
var maxOptLen = options.Max(o => o.Template.Length);
var maxOptLen = options.Max(o => o.GetDisplayText().Length);
var outputFormat = string.Format(CultureInfo.InvariantCulture, " {{0, -{0}}}{{1}}", maxOptLen + 2);
foreach (var opt in options)
{
optionsBuilder.AppendFormat(CultureInfo.InvariantCulture, outputFormat, opt.Template, opt.Description);
optionsBuilder.AppendFormat(CultureInfo.InvariantCulture, outputFormat, opt.GetDisplayText(), opt.Description);
optionsBuilder.AppendLine();
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/Shared/CommandLineUtils/CommandLine/CommandOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ public string Value()
return HasValue() ? Values[0] : null;
}

public string GetDisplayText()
{
var parts = new List<string>();

if (!string.IsNullOrEmpty(SymbolName))
{
parts.Add($"-{SymbolName}");
}

if (!string.IsNullOrEmpty(ShortName))
{
parts.Add($"-{ShortName}");
}

if (!string.IsNullOrEmpty(LongName))
{
parts.Add($"--{LongName}");
}

var result = string.Join(", ", parts);

if (!string.IsNullOrEmpty(ValueName))
{
result += $" <{ValueName}>";
}

return result;
}

private static bool IsEnglishLetter(char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
Expand Down
Loading