Skip to content

Commit 7ee7342

Browse files
authored
Replicate change from dotnet/command-line-api#2586 (#49520)
1 parent 639cdb1 commit 7ee7342

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Cli/Microsoft.TemplateEngine.Cli/Help/HelpBuilder.Default.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,22 @@ public static string GetArgumentUsageLabel(Symbol parameter)
5050
// By default Option.Name == Argument.Name, don't repeat it
5151
return parameter switch
5252
{
53-
Argument argument => GetUsageLabel(argument.HelpName, argument.ValueType, argument.CompletionSources, argument) ?? $"<{argument.Name}>",
54-
Option option => GetUsageLabel(option.HelpName, option.ValueType, option.CompletionSources, option) ?? "",
53+
Argument argument => GetUsageLabel(argument.HelpName, argument.ValueType, argument.CompletionSources, argument, argument.Arity) ?? $"<{argument.Name}>",
54+
Option option => GetUsageLabel(option.HelpName, option.ValueType, option.CompletionSources, option, option.Arity) ?? "",
5555
_ => throw new InvalidOperationException()
5656
};
5757

58-
static string? GetUsageLabel(string? helpName, Type valueType, List<Func<CompletionContext, IEnumerable<CompletionItem>>> completionSources, Symbol symbol)
58+
static string? GetUsageLabel(string? helpName, Type valueType, List<Func<CompletionContext, IEnumerable<CompletionItem>>> completionSources, Symbol symbol, ArgumentArity arity)
5959
{
6060
// Argument.HelpName is always first choice
6161
if (!string.IsNullOrWhiteSpace(helpName))
6262
{
6363
return $"<{helpName}>";
6464
}
65-
else if (!(valueType == typeof(bool) || valueType == typeof(bool?)) && completionSources.Count > 0)
65+
else if (
66+
!(valueType == typeof(bool) || valueType == typeof(bool?))
67+
&& arity.MaximumNumberOfValues > 0 // allowing zero arguments means we don't need to show usage
68+
&& completionSources.Count > 0)
6669
{
6770
IEnumerable<string> completions = symbol
6871
.GetCompletions(CompletionContext.Empty)

0 commit comments

Comments
 (0)