Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally trim trailing periods of argument and option descriptions #1740

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Spectre.Console.Cli/ConfiguratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static IConfigurator UseStrictParsing(this IConfigurator configurator)
}

/// <summary>
/// Tells the help writer whether or not to trim trailing period.
/// Tells the help provider whether or not to trim trailing period.
/// </summary>
/// <param name="configurator">The configurator.</param>
/// <param name="trimTrailingPeriods">True to trim trailing period (default), false to not.</param>
Expand Down
37 changes: 20 additions & 17 deletions src/Spectre.Console.Cli/Help/HelpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class HelpProvider : IHelpProvider
protected virtual bool ShowOptionDefaultValues { get; }

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

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

var composer = NewComposer();
composer.Style(helpStyles?.Description?.Header ?? Style.Plain, $"{resources.Description}:").LineBreak();
composer.Text(command.Description).LineBreak();
composer.Text(NormalizeDescription(command.Description)).LineBreak();
yield return composer.LineBreak();
}

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

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

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

columns.Add(NewComposer().Text(option.Description?.TrimEnd('.') ?? " "));
columns.Add(NewComposer().Text(NormalizeDescription(option.Description)));

grid.AddRow(columns.ToArray());
}
Expand Down Expand Up @@ -478,18 +478,9 @@ public virtual IEnumerable<IRenderable> GetCommands(ICommandModel model, IComman
arguments.Space();
}

if (TrimTrailingPeriod)
{
grid.AddRow(
NewComposer().Text(arguments.ToString().TrimEnd()),
NewComposer().Text(child.Description?.TrimEnd('.') ?? " "));
}
else
{
grid.AddRow(
NewComposer().Text(arguments.ToString().TrimEnd()),
NewComposer().Text(child.Description ?? " "));
}
grid.AddRow(
NewComposer().Text(arguments.ToString().TrimEnd()),
NewComposer().Text(NormalizeDescription(child.Description)));
}

result.Add(grid);
Expand Down Expand Up @@ -566,4 +557,16 @@ private Composer GetDefaultValueForOption(object? defaultValue)
_ => NewComposer().Style(helpStyles?.Options?.DefaultValue ?? Style.Plain, defaultValue?.ToString() ?? string.Empty),
};
}

private string NormalizeDescription(string? description)
{
if (description == null)
{
return " ";
}

return TrimTrailingPeriod
? description.TrimEnd('.')
: description;
}
}
2 changes: 1 addition & 1 deletion src/Spectre.Console.Cli/ICommandAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface ICommandAppSettings
bool ShowOptionDefaultValues { get; set; }

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

Expand Down
6 changes: 3 additions & 3 deletions src/Spectre.Console.Cli/Resources/HelpProvider.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPTIONEN</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Zeigt Hilfe an</value>
<value>Zeigt Hilfe an.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Zeigt Versionsinformationen an</value>
<value>Zeigt Versionsinformationen an.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>VERWENDUNG</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPCIONES</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Imprime información de ayuda</value>
<value>Imprime información de ayuda.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Imprime información de versión</value>
<value>Imprime información de versión.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>USO</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPTIONS</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Affiche l'aide</value>
<value>Affiche l'aide.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Affiche la version</value>
<value>Affiche la version.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>UTILISATION</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPZIONI</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Visualizza le informazioni di aiuto</value>
<value>Visualizza le informazioni di aiuto.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Visualizza le informazioni sulla versione</value>
<value>Visualizza le informazioni sulla versione.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>USO</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.pt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPÇÕES</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Exibe informações de ajuda</value>
<value>Exibe informações de ajuda.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Exibe informações de versão</value>
<value>Exibe informações de versão.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>USO</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>OPTIONS</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Prints help information</value>
<value>Prints help information.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Prints version information</value>
<value>Prints version information.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>USAGE</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>ОПЦИИ</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Выводит информацию о помощи</value>
<value>Выводит информацию о помощи.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Выводит информацию о версии</value>
<value>Выводит информацию о версии.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>ИСПОЛЬЗОВАНИЕ</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console.Cli/Resources/HelpProvider.sv.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
<value>VAL</value>
</data>
<data name="PrintHelpDescription" xml:space="preserve">
<value>Skriver ut hjälpinformation</value>
<value>Skriver ut hjälpinformation.</value>
</data>
<data name="PrintVersionDescription" xml:space="preserve">
<value>Skriver ut versionsnummer</value>
<value>Skriver ut versionsnummer.</value>
</data>
<data name="Usage" xml:space="preserve">
<value>ANVÄNDING</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
Contains settings for a cat.
Contains settings for a cat

USAGE:
myapp cat [LEGS] [OPTIONS] <COMMAND>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
Contains settings for a cat.
Contains settings for a cat

USAGE:
myapp cat [LEGS] [OPTIONS] <COMMAND>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The animal command.
The animal command

USAGE:
myapp animal [LEGS] [OPTIONS] <COMMAND>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
Contains settings for a cat.
Contains settings for a cat

USAGE:
myapp cat [LEGS] [OPTIONS] <COMMAND>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The lion command.
The lion command

USAGE:
myapp <TEETH> [LEGS] [OPTIONS]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The dog command.
The dog command

USAGE:
myapp <AGE> [LEGS] [OPTIONS]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The lion command.
The lion command

USAGE:
myapp <TEETH> [LEGS] [OPTIONS]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BESCHREIBUNG:
The lion command.
The lion command

VERWENDUNG:
myapp <TEETH> [LEGS] [OPTIONEN] [KOMMANDO]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The lion command.
The lion command

USAGE:
myapp <TEETH> [LEGS] [OPTIONS] [COMMAND]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
The lion command.
The lion command

UTILISATION:
myapp <TEETH> [LEGS] [OPTIONS] [COMMANDE]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIZIONE:
The lion command.
The lion command

USO:
myapp <TEETH> [LEGS] [OPZIONI] [COMANDO]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
説明:
The lion command.
The lion command

使用法:
myapp <TEETH> [LEGS] [オプション] [コマンド]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
설명:
The lion command.
The lion command

사용법:
myapp <TEETH> [LEGS] [옵션] [명령]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIÇÃO:
The lion command.
The lion command

USO:
myapp <TEETH> [LEGS] [OPÇÕES] [COMANDO]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ОПИСАНИЕ:
The lion command.
The lion command

ИСПОЛЬЗОВАНИЕ:
myapp <TEETH> [LEGS] [ОПЦИИ] [КОМАНДА]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BESKRIVNING:
The lion command.
The lion command

ANVÄNDING:
myapp <TEETH> [LEGS] [VAL] [KOMMANDO]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
描述:
The lion command.
The lion command

用法:
myapp <TEETH> [LEGS] [选项] [命令]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bold]DESCRIPTION:[/]
The lion command.
The lion command

[bold]USAGE:[/]
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[yellow]DESCRIPTION:[/]
The lion command.
The lion command

[yellow]USAGE:[/]
myapp [aqua]<TEETH>[/] [silver][[LEGS]][/] [grey][[OPTIONS]][/] [aqua][[COMMAND]][/]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[]DESCRIPTION:[/]
The lion command.
The lion command

[]USAGE:[/]
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
USAGE:
myapp [OPTIONS] <COMMAND>
DESCRIPTION:
The dog command.

OPTIONS:
-h, --help Prints help information
USAGE:
myapp dog <AGE> [LEGS] [OPTIONS]

ARGUMENTS:
<AGE>
[LEGS] The number of legs.

COMMANDS:
dog <AGE> The dog command.
horse The horse command.
OPTIONS:
-h, --help Prints help information.
-a, --alive Indicates whether or not the animal is alive.
-n, --name <VALUE>
-g, --good-boy
Loading