mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-16 04:03:22 +08:00
Conditionally trim trailing periods of argument and option descriptions (#1740)
This commit is contained in:
parent
c1eb94c1db
commit
11a320c7c9
@ -168,7 +168,7 @@ public static class ConfiguratorExtensions
|
||||
}
|
||||
|
||||
/// <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>
|
||||
|
@ -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; }
|
||||
|
||||
@ -171,7 +171,7 @@ public class HelpProvider : IHelpProvider
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -364,14 +364,14 @@ public class HelpProvider : IHelpProvider
|
||||
{
|
||||
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);
|
||||
@ -428,7 +428,7 @@ public class HelpProvider : IHelpProvider
|
||||
columns.Add(GetDefaultValueForOption(option.DefaultValue));
|
||||
}
|
||||
|
||||
columns.Add(NewComposer().Text(option.Description?.TrimEnd('.') ?? " "));
|
||||
columns.Add(NewComposer().Text(NormalizeDescription(option.Description)));
|
||||
|
||||
grid.AddRow(columns.ToArray());
|
||||
}
|
||||
@ -478,18 +478,9 @@ public class HelpProvider : IHelpProvider
|
||||
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);
|
||||
@ -566,4 +557,16 @@ public class HelpProvider : IHelpProvider
|
||||
_ => 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;
|
||||
}
|
||||
}
|
@ -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; }
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
@ -124,7 +124,7 @@ namespace Spectre.Console.Cli.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Prints help information.
|
||||
/// Looks up a localized string similar to Prints help information..
|
||||
/// </summary>
|
||||
internal static string PrintHelpDescription {
|
||||
get {
|
||||
@ -133,7 +133,7 @@ namespace Spectre.Console.Cli.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Prints version information.
|
||||
/// Looks up a localized string similar to Prints version information..
|
||||
/// </summary>
|
||||
internal static string PrintVersionDescription {
|
||||
get {
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
Contains settings for a cat.
|
||||
Contains settings for a cat
|
||||
|
||||
USAGE:
|
||||
myapp cat [LEGS] [OPTIONS] <COMMAND>
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
Contains settings for a cat.
|
||||
Contains settings for a cat
|
||||
|
||||
USAGE:
|
||||
myapp cat [LEGS] [OPTIONS] <COMMAND>
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The animal command.
|
||||
The animal command
|
||||
|
||||
USAGE:
|
||||
myapp animal [LEGS] [OPTIONS] <COMMAND>
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
Contains settings for a cat.
|
||||
Contains settings for a cat
|
||||
|
||||
USAGE:
|
||||
myapp cat [LEGS] [OPTIONS] <COMMAND>
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USAGE:
|
||||
myapp <TEETH> [LEGS] [OPTIONS]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The dog command.
|
||||
The dog command
|
||||
|
||||
USAGE:
|
||||
myapp <AGE> [LEGS] [OPTIONS]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USAGE:
|
||||
myapp <TEETH> [LEGS] [OPTIONS]
|
||||
|
@ -1,5 +1,5 @@
|
||||
BESCHREIBUNG:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
VERWENDUNG:
|
||||
myapp <TEETH> [LEGS] [OPTIONEN] [KOMMANDO]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USAGE:
|
||||
myapp <TEETH> [LEGS] [OPTIONS] [COMMAND]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
UTILISATION:
|
||||
myapp <TEETH> [LEGS] [OPTIONS] [COMMANDE]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIZIONE:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USO:
|
||||
myapp <TEETH> [LEGS] [OPZIONI] [COMANDO]
|
||||
|
@ -1,5 +1,5 @@
|
||||
説明:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
使用法:
|
||||
myapp <TEETH> [LEGS] [オプション] [コマンド]
|
||||
|
@ -1,5 +1,5 @@
|
||||
설명:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
사용법:
|
||||
myapp <TEETH> [LEGS] [옵션] [명령]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIÇÃO:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USO:
|
||||
myapp <TEETH> [LEGS] [OPÇÕES] [COMANDO]
|
||||
|
@ -1,5 +1,5 @@
|
||||
ОПИСАНИЕ:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
ИСПОЛЬЗОВАНИЕ:
|
||||
myapp <TEETH> [LEGS] [ОПЦИИ] [КОМАНДА]
|
||||
|
@ -1,5 +1,5 @@
|
||||
BESKRIVNING:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
ANVÄNDING:
|
||||
myapp <TEETH> [LEGS] [VAL] [KOMMANDO]
|
||||
|
@ -1,5 +1,5 @@
|
||||
描述:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
用法:
|
||||
myapp <TEETH> [LEGS] [选项] [命令]
|
||||
|
@ -1,5 +1,5 @@
|
||||
[bold]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
[bold]USAGE:[/]
|
||||
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
|
||||
|
@ -1,5 +1,5 @@
|
||||
[yellow]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
[yellow]USAGE:[/]
|
||||
myapp [aqua]<TEETH>[/] [silver][[LEGS]][/] [grey][[OPTIONS]][/] [aqua][[COMMAND]][/]
|
||||
|
@ -1,5 +1,5 @@
|
||||
[]DESCRIPTION:[/]
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
[]USAGE:[/]
|
||||
myapp []<TEETH>[/] [][[LEGS]][/] [][[OPTIONS]][/] [][[COMMAND]][/]
|
||||
|
@ -1,9 +1,15 @@
|
||||
USAGE:
|
||||
myapp [OPTIONS] <COMMAND>
|
||||
DESCRIPTION:
|
||||
The dog command.
|
||||
|
||||
USAGE:
|
||||
myapp dog <AGE> [LEGS] [OPTIONS]
|
||||
|
||||
ARGUMENTS:
|
||||
<AGE>
|
||||
[LEGS] The number of legs.
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Prints help information
|
||||
|
||||
COMMANDS:
|
||||
dog <AGE> The dog command.
|
||||
horse The horse command.
|
||||
-h, --help Prints help information.
|
||||
-a, --alive Indicates whether or not the animal is alive.
|
||||
-n, --name <VALUE>
|
||||
-g, --good-boy
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The lion command.
|
||||
The lion command
|
||||
|
||||
USAGE:
|
||||
myapp cat [LEGS] lion <TEETH> [OPTIONS]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The horse command.
|
||||
The horse command
|
||||
|
||||
USAGE:
|
||||
myapp horse [LEGS] [OPTIONS]
|
||||
|
@ -1,5 +1,5 @@
|
||||
DESCRIPTION:
|
||||
The horse command.
|
||||
The horse command
|
||||
|
||||
USAGE:
|
||||
myapp horse [LEGS] [OPTIONS]
|
||||
|
@ -132,7 +132,7 @@ public sealed partial class CommandAppTests
|
||||
});
|
||||
|
||||
// When
|
||||
var result = fixture.Run("--help");
|
||||
var result = fixture.Run("dog", "--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(result.Output);
|
||||
|
Loading…
x
Reference in New Issue
Block a user