Skip to content

Commit 11a320c

Browse files
authored
Conditionally trim trailing periods of argument and option descriptions (#1740)
1 parent c1eb94c commit 11a320c

File tree

37 files changed

+78
-69
lines changed

37 files changed

+78
-69
lines changed

src/Spectre.Console.Cli/ConfiguratorExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static IConfigurator UseStrictParsing(this IConfigurator configurator)
168168
}
169169

170170
/// <summary>
171-
/// Tells the help writer whether or not to trim trailing period.
171+
/// Tells the help provider whether or not to trim trailing period.
172172
/// </summary>
173173
/// <param name="configurator">The configurator.</param>
174174
/// <param name="trimTrailingPeriods">True to trim trailing period (default), false to not.</param>

src/Spectre.Console.Cli/Help/HelpProvider.cs

+20-17
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class HelpProvider : IHelpProvider
2222
protected virtual bool ShowOptionDefaultValues { get; }
2323

2424
/// <summary>
25-
/// Gets a value indicating whether a trailing period of a command description is trimmed in the help text.
25+
/// Gets a value indicating whether a trailing period of a description is trimmed in the help text.
2626
/// </summary>
2727
protected virtual bool TrimTrailingPeriod { get; }
2828

@@ -171,7 +171,7 @@ public virtual IEnumerable<IRenderable> GetDescription(ICommandModel model, ICom
171171

172172
var composer = NewComposer();
173173
composer.Style(helpStyles?.Description?.Header ?? Style.Plain, $"{resources.Description}:").LineBreak();
174-
composer.Text(command.Description).LineBreak();
174+
composer.Text(NormalizeDescription(command.Description)).LineBreak();
175175
yield return composer.LineBreak();
176176
}
177177

@@ -364,14 +364,14 @@ public virtual IEnumerable<IRenderable> GetArguments(ICommandModel model, IComma
364364
{
365365
grid.AddRow(
366366
NewComposer().Style(helpStyles?.Arguments?.RequiredArgument ?? Style.Plain, $"<{argument.Name}>"),
367-
NewComposer().Text(argument.Description?.TrimEnd('.') ?? " "));
367+
NewComposer().Text(NormalizeDescription(argument.Description)));
368368
}
369369

370370
foreach (var argument in arguments.Where(x => !x.Required).OrderBy(x => x.Position))
371371
{
372372
grid.AddRow(
373373
NewComposer().Style(helpStyles?.Arguments?.OptionalArgument ?? Style.Plain, $"[{argument.Name}]"),
374-
NewComposer().Text(argument.Description?.TrimEnd('.') ?? " "));
374+
NewComposer().Text(NormalizeDescription(argument.Description)));
375375
}
376376

377377
result.Add(grid);
@@ -428,7 +428,7 @@ public virtual IEnumerable<IRenderable> GetOptions(ICommandModel model, ICommand
428428
columns.Add(GetDefaultValueForOption(option.DefaultValue));
429429
}
430430

431-
columns.Add(NewComposer().Text(option.Description?.TrimEnd('.') ?? " "));
431+
columns.Add(NewComposer().Text(NormalizeDescription(option.Description)));
432432

433433
grid.AddRow(columns.ToArray());
434434
}
@@ -478,18 +478,9 @@ public virtual IEnumerable<IRenderable> GetCommands(ICommandModel model, IComman
478478
arguments.Space();
479479
}
480480

481-
if (TrimTrailingPeriod)
482-
{
483-
grid.AddRow(
484-
NewComposer().Text(arguments.ToString().TrimEnd()),
485-
NewComposer().Text(child.Description?.TrimEnd('.') ?? " "));
486-
}
487-
else
488-
{
489-
grid.AddRow(
490-
NewComposer().Text(arguments.ToString().TrimEnd()),
491-
NewComposer().Text(child.Description ?? " "));
492-
}
481+
grid.AddRow(
482+
NewComposer().Text(arguments.ToString().TrimEnd()),
483+
NewComposer().Text(NormalizeDescription(child.Description)));
493484
}
494485

495486
result.Add(grid);
@@ -566,4 +557,16 @@ private Composer GetDefaultValueForOption(object? defaultValue)
566557
_ => NewComposer().Style(helpStyles?.Options?.DefaultValue ?? Style.Plain, defaultValue?.ToString() ?? string.Empty),
567558
};
568559
}
560+
561+
private string NormalizeDescription(string? description)
562+
{
563+
if (description == null)
564+
{
565+
return " ";
566+
}
567+
568+
return TrimTrailingPeriod
569+
? description.TrimEnd('.')
570+
: description;
571+
}
569572
}

src/Spectre.Console.Cli/ICommandAppSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface ICommandAppSettings
3737
bool ShowOptionDefaultValues { get; set; }
3838

3939
/// <summary>
40-
/// Gets or sets a value indicating whether a trailing period of a command description is trimmed in the help text.
40+
/// Gets or sets a value indicating whether a trailing period of a description is trimmed in the help text.
4141
/// </summary>
4242
bool TrimTrailingPeriod { get; set; }
4343

src/Spectre.Console.Cli/Resources/HelpProvider.Designer.cs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Spectre.Console.Cli/Resources/HelpProvider.de.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPTIONEN</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Zeigt Hilfe an</value>
142+
<value>Zeigt Hilfe an.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Zeigt Versionsinformationen an</value>
145+
<value>Zeigt Versionsinformationen an.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>VERWENDUNG</value>

src/Spectre.Console.Cli/Resources/HelpProvider.es.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPCIONES</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Imprime información de ayuda</value>
142+
<value>Imprime información de ayuda.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Imprime información de versión</value>
145+
<value>Imprime información de versión.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>USO</value>

src/Spectre.Console.Cli/Resources/HelpProvider.fr.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPTIONS</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Affiche l'aide</value>
142+
<value>Affiche l'aide.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Affiche la version</value>
145+
<value>Affiche la version.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>UTILISATION</value>

src/Spectre.Console.Cli/Resources/HelpProvider.it.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPZIONI</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Visualizza le informazioni di aiuto</value>
142+
<value>Visualizza le informazioni di aiuto.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Visualizza le informazioni sulla versione</value>
145+
<value>Visualizza le informazioni sulla versione.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>USO</value>

src/Spectre.Console.Cli/Resources/HelpProvider.pt.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPÇÕES</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Exibe informações de ajuda</value>
142+
<value>Exibe informações de ajuda.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Exibe informações de versão</value>
145+
<value>Exibe informações de versão.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>USO</value>

src/Spectre.Console.Cli/Resources/HelpProvider.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>OPTIONS</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Prints help information</value>
142+
<value>Prints help information.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Prints version information</value>
145+
<value>Prints version information.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>USAGE</value>

src/Spectre.Console.Cli/Resources/HelpProvider.ru.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>ОПЦИИ</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Выводит информацию о помощи</value>
142+
<value>Выводит информацию о помощи.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Выводит информацию о версии</value>
145+
<value>Выводит информацию о версии.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>ИСПОЛЬЗОВАНИЕ</value>

src/Spectre.Console.Cli/Resources/HelpProvider.sv.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
<value>VAL</value>
140140
</data>
141141
<data name="PrintHelpDescription" xml:space="preserve">
142-
<value>Skriver ut hjälpinformation</value>
142+
<value>Skriver ut hjälpinformation.</value>
143143
</data>
144144
<data name="PrintVersionDescription" xml:space="preserve">
145-
<value>Skriver ut versionsnummer</value>
145+
<value>Skriver ut versionsnummer.</value>
146146
</data>
147147
<data name="Usage" xml:space="preserve">
148148
<value>ANVÄNDING</value>

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Branch.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
Contains settings for a cat.
2+
Contains settings for a cat
33

44
USAGE:
55
myapp cat [LEGS] [OPTIONS] <COMMAND>

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Branch_Called_Without_Help.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
Contains settings for a cat.
2+
Contains settings for a cat
33

44
USAGE:
55
myapp cat [LEGS] [OPTIONS] <COMMAND>

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Branch_Examples.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The animal command.
2+
The animal command
33

44
USAGE:
55
myapp animal [LEGS] [OPTIONS] <COMMAND>

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Command_Hide_Default.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
Contains settings for a cat.
2+
Contains settings for a cat
33

44
USAGE:
55
myapp cat [LEGS] [OPTIONS] <COMMAND>

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The lion command.
2+
The lion command
33

44
USAGE:
55
myapp <TEETH> [LEGS] [OPTIONS]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Examples.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The dog command.
2+
The dog command
33

44
USAGE:
55
myapp <AGE> [LEGS] [OPTIONS]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The lion command.
2+
The lion command
33

44
USAGE:
55
myapp <TEETH> [LEGS] [OPTIONS]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_DE.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BESCHREIBUNG:
2-
The lion command.
2+
The lion command
33

44
VERWENDUNG:
55
myapp <TEETH> [LEGS] [OPTIONEN] [KOMMANDO]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_EN.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The lion command.
2+
The lion command
33

44
USAGE:
55
myapp <TEETH> [LEGS] [OPTIONS] [COMMAND]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_FR.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
The lion command.
2+
The lion command
33

44
UTILISATION:
55
myapp <TEETH> [LEGS] [OPTIONS] [COMMANDE]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_IT.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIZIONE:
2-
The lion command.
2+
The lion command
33

44
USO:
55
myapp <TEETH> [LEGS] [OPZIONI] [COMANDO]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_JA.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
説明:
2-
The lion command.
2+
The lion command
33

44
使用法:
55
myapp <TEETH> [LEGS] [オプション] [コマンド]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_KO.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
설명:
2-
The lion command.
2+
The lion command
33

44
사용법:
55
myapp <TEETH> [LEGS] [옵션] [명령]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_PT.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIÇÃO:
2-
The lion command.
2+
The lion command
33

44
USO:
55
myapp <TEETH> [LEGS] [OPÇÕES] [COMANDO]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_RU.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ОПИСАНИЕ:
2-
The lion command.
2+
The lion command
33

44
ИСПОЛЬЗОВАНИЕ:
55
myapp <TEETH> [LEGS] [ОПЦИИ] [КОМАНДА]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_SV.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BESKRIVNING:
2-
The lion command.
2+
The lion command
33

44
ANVÄNDING:
55
myapp <TEETH> [LEGS] [VAL] [KOMMANDO]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_ZH-HANS.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
描述:
2-
The lion command.
2+
The lion command
33

44
用法:
55
myapp <TEETH> [LEGS] [选项] [命令]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional_Style_BoldHeadings.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bold]DESCRIPTION:[/]
2-
The lion command.
2+
The lion command
33

44
[bold]USAGE:[/]
55
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional_Style_Default.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[yellow]DESCRIPTION:[/]
2-
The lion command.
2+
The lion command
33

44
[yellow]USAGE:[/]
55
myapp [aqua]<TEETH>[/] [silver][[LEGS]][/] [grey][[OPTIONS]][/] [aqua][[COMMAND]][/]

src/Tests/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional_Style_None.Output.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[]DESCRIPTION:[/]
2-
The lion command.
2+
The lion command
33

44
[]USAGE:[/]
55
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
USAGE:
2-
myapp [OPTIONS] <COMMAND>
1+
DESCRIPTION:
2+
The dog command.
33

4-
OPTIONS:
5-
-h, --help Prints help information
4+
USAGE:
5+
myapp dog <AGE> [LEGS] [OPTIONS]
6+
7+
ARGUMENTS:
8+
<AGE>
9+
[LEGS] The number of legs.
610

7-
COMMANDS:
8-
dog <AGE> The dog command.
9-
horse The horse command.
11+
OPTIONS:
12+
-h, --help Prints help information.
13+
-a, --alive Indicates whether or not the animal is alive.
14+
-n, --name <VALUE>
15+
-g, --good-boy

0 commit comments

Comments
 (0)