Skip to content

Commit b50413b

Browse files
committed
Do not show suggestions in help if too long
1 parent d2203f9 commit b50413b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/System.CommandLine.Tests/Help/HelpBuilderTests.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,38 @@ public void Arguments_section_includes_configured_argument_aliases()
469469
help.Should().Contain("Sets the verbosity.");
470470
}
471471

472+
473+
private enum VerbosityOptions
474+
{
475+
quiet,
476+
q,
477+
minimal,
478+
m,
479+
normal,
480+
n,
481+
detailed,
482+
d,
483+
diagnostic,
484+
diag
485+
}
486+
487+
[Fact]
488+
public void Arguments_section_uses_name_if_suggestions_are_long()
489+
{
490+
var command = new Command("the-command")
491+
{
492+
new Option<VerbosityOptions>(new[] { "-v", "--verbosity" })
493+
{
494+
ArgumentHelpName = "LEVEL"
495+
}
496+
};
497+
498+
_helpBuilder.Write(command);
499+
500+
var help = _console.Out.ToString();
501+
help.Should().Contain("-v, --verbosity <LEVEL>");
502+
}
503+
472504
[Fact]
473505
public void Arguments_section_uses_description_if_provided()
474506
{
@@ -1240,7 +1272,7 @@ public void Help_describes_default_value_for_option_with_argument_having_default
12401272

12411273
help.Should().Contain($"[default: the-arg-value]");
12421274
}
1243-
1275+
12441276
[Fact]
12451277
public void Option_arguments_with_default_values_that_are_enumerable_display_pipe_delimited_list()
12461278
{

src/System.CommandLine/Help/HelpBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ protected string GetArgumentDescriptor(IArgument argument)
522522

523523
string descriptor;
524524
var suggestions = argument.GetSuggestions().ToArray();
525-
if (suggestions.Length > 0)
525+
if (suggestions.Length > 0 && string.Join("|", suggestions).Length < 50)
526526
{
527527
descriptor = string.Join("|", suggestions);
528528
}

0 commit comments

Comments
 (0)