diff --git a/src/Spectre.Console.Cli/ConfiguratorExtensions.cs b/src/Spectre.Console.Cli/ConfiguratorExtensions.cs index 1a27e5aa3..9c6219418 100644 --- a/src/Spectre.Console.Cli/ConfiguratorExtensions.cs +++ b/src/Spectre.Console.Cli/ConfiguratorExtensions.cs @@ -39,7 +39,30 @@ public static IConfigurator SetHelpProvider(this IConfigurator configurator) configurator.SetHelpProvider(); return configurator; - } + } + + /// + /// Sets the culture for the application. + /// + /// The configurator. + /// The culture. + /// A configurator that can be used to configure the application further. + /// + /// Text displayed by can be localised, but defaults to English. + /// Setting the application culture informs the resource manager which culture to use when fetching strings. + /// English will be used when a culture has not been specified + /// or a string has not been localised for the specified culture. + /// + public static IConfigurator SetApplicationCulture(this IConfigurator configurator, CultureInfo? culture) + { + if (configurator == null) + { + throw new ArgumentNullException(nameof(configurator)); + } + + configurator.Settings.Culture = culture; + return configurator; + } /// /// Sets the name of the application. diff --git a/src/Spectre.Console.Cli/Help/HelpProvider.cs b/src/Spectre.Console.Cli/Help/HelpProvider.cs index f9a28b8b8..0c8ad6782 100644 --- a/src/Spectre.Console.Cli/Help/HelpProvider.cs +++ b/src/Spectre.Console.Cli/Help/HelpProvider.cs @@ -1,3 +1,5 @@ +using Spectre.Console.Cli.Resources; + namespace Spectre.Console.Cli.Help; /// @@ -7,7 +9,9 @@ namespace Spectre.Console.Cli.Help; /// Other IHelpProvider implementations can be injected into the CommandApp, if desired. /// public class HelpProvider : IHelpProvider -{ +{ + private HelpProviderResources resources; + /// /// Gets a value indicating how many examples from direct children to show in the help text. /// @@ -67,17 +71,17 @@ public HelpOption(string? @short, string? @long, string? @value, bool? valueIsOp DefaultValue = defaultValue; } - public static IReadOnlyList Get(ICommandInfo? command) + public static IReadOnlyList Get(ICommandInfo? command, HelpProviderResources resources) { var parameters = new List(); - parameters.Add(new HelpOption("h", "help", null, null, "Prints help information", null)); + parameters.Add(new HelpOption("h", "help", null, null, resources.PrintHelpDescription, null)); // Version information applies to the entire application // Include the "-v" option in the help when at the root of the command line application // Don't allow the "-v" option if users have specified one or more sub-commands if ((command == null || command?.Parent == null) && !(command?.IsBranch ?? false)) { - parameters.Add(new HelpOption("v", "version", null, null, "Prints version information", null)); + parameters.Add(new HelpOption("v", "version", null, null, resources.PrintVersionDescription, null)); } parameters.AddRange(command?.Parameters.OfType().Where(o => !o.IsHidden).Select(o => @@ -98,7 +102,9 @@ public HelpProvider(ICommandAppSettings settings) { this.ShowOptionDefaultValues = settings.ShowOptionDefaultValues; this.MaximumIndirectExamples = settings.MaximumIndirectExamples; - this.TrimTrailingPeriod = settings.TrimTrailingPeriod; + this.TrimTrailingPeriod = settings.TrimTrailingPeriod; + + resources = new HelpProviderResources(settings.Culture); } /// @@ -143,7 +149,7 @@ public virtual IEnumerable GetDescription(ICommandModel model, ICom } var composer = new Composer(); - composer.Style("yellow", "DESCRIPTION:").LineBreak(); + composer.Style("yellow", $"{resources.Description}:").LineBreak(); composer.Text(command.Description).LineBreak(); yield return composer.LineBreak(); } @@ -157,15 +163,15 @@ public virtual IEnumerable GetDescription(ICommandModel model, ICom public virtual IEnumerable GetUsage(ICommandModel model, ICommandInfo? command) { var composer = new Composer(); - composer.Style("yellow", "USAGE:").LineBreak(); + composer.Style("yellow", $"{resources.Usage}:").LineBreak(); composer.Tab().Text(model.ApplicationName); var parameters = new List(); if (command == null) { - parameters.Add("[grey][[OPTIONS]][/]"); - parameters.Add("[aqua][/]"); + parameters.Add($"[grey][[{resources.Options}]][/]"); + parameters.Add($"[aqua]<{resources.Command}>[/]"); } else { @@ -208,20 +214,20 @@ public virtual IEnumerable GetUsage(ICommandModel model, ICommandIn if (isCurrent) { - parameters.Add("[grey][[OPTIONS]][/]"); + parameters.Add($"[grey][[{resources.Options}]][/]"); } } if (command.IsBranch && command.DefaultCommand == null) { // The user must specify the command - parameters.Add("[aqua][/]"); + parameters.Add($"[aqua]<{resources.Command}>[/]"); } else if (command.IsBranch && command.DefaultCommand != null && command.Commands.Count > 0) { // We are on a branch with a default command // The user can optionally specify the command - parameters.Add("[aqua][[COMMAND]][/]"); + parameters.Add($"[aqua][[{resources.Command}]][/]"); } else if (command.IsDefaultCommand) { @@ -231,7 +237,7 @@ public virtual IEnumerable GetUsage(ICommandModel model, ICommandIn { // Commands other than the default are present // So make these optional in the usage statement - parameters.Add("[aqua][[COMMAND]][/]"); + parameters.Add($"[aqua][[{resources.Command}]][/]"); } } } @@ -298,7 +304,7 @@ public virtual IEnumerable GetExamples(ICommandModel model, IComman { var composer = new Composer(); composer.LineBreak(); - composer.Style("yellow", "EXAMPLES:").LineBreak(); + composer.Style("yellow", $"{resources.Examples}:").LineBreak(); for (var index = 0; index < Math.Min(maxExamples, examples.Count); index++) { @@ -330,7 +336,7 @@ public virtual IEnumerable GetArguments(ICommandModel model, IComma var result = new List { new Markup(Environment.NewLine), - new Markup("[yellow]ARGUMENTS:[/]"), + new Markup($"[yellow]{resources.Arguments}:[/]"), new Markup(Environment.NewLine), }; @@ -366,7 +372,7 @@ public virtual IEnumerable GetArguments(ICommandModel model, IComma public virtual IEnumerable GetOptions(ICommandModel model, ICommandInfo? command) { // Collect all options into a single structure. - var parameters = HelpOption.Get(command); + var parameters = HelpOption.Get(command, resources); if (parameters.Count == 0) { return Array.Empty(); @@ -375,7 +381,7 @@ public virtual IEnumerable GetOptions(ICommandModel model, ICommand var result = new List { new Markup(Environment.NewLine), - new Markup("[yellow]OPTIONS:[/]"), + new Markup($"[yellow]{resources.Options}:[/]"), new Markup(Environment.NewLine), }; @@ -434,7 +440,7 @@ static string GetOptionParts(HelpOption option) if (defaultValueColumn) { - grid.AddRow(" ", "[lime]DEFAULT[/]", " "); + grid.AddRow(" ", $"[lime]{resources.Default}[/]", " "); } foreach (var option in helpOptions) @@ -487,7 +493,7 @@ public virtual IEnumerable GetCommands(ICommandModel model, IComman var result = new List { new Markup(Environment.NewLine), - new Markup("[yellow]COMMANDS:[/]"), + new Markup($"[yellow]{resources.Commands}:[/]"), new Markup(Environment.NewLine), }; diff --git a/src/Spectre.Console.Cli/Help/HelpProviderResources.cs b/src/Spectre.Console.Cli/Help/HelpProviderResources.cs new file mode 100644 index 000000000..890e24857 --- /dev/null +++ b/src/Spectre.Console.Cli/Help/HelpProviderResources.cs @@ -0,0 +1,131 @@ +using System.Resources; + +namespace Spectre.Console.Cli.Help; + +/// +/// A strongly-typed resource class, for looking up localized strings, etc. +/// +internal class HelpProviderResources +{ + private readonly ResourceManager resourceManager = new ResourceManager("Spectre.Console.Cli.Resources.HelpProvider", typeof(HelpProvider).Assembly); + private readonly CultureInfo? resourceCulture = null; + + public HelpProviderResources() + { + } + + public HelpProviderResources(CultureInfo? culture) + { + resourceCulture = culture; + } + + /// + /// Gets the localised string for ARGUMENTS. + /// + internal string Arguments + { + get + { + return resourceManager.GetString("Arguments", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for COMMAND. + /// + internal string Command + { + get + { + return resourceManager.GetString("Command", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for COMMANDS. + /// + internal string Commands + { + get + { + return resourceManager.GetString("Commands", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for DEFAULT. + /// + internal string Default + { + get + { + return resourceManager.GetString("Default", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for DESCRIPTION. + /// + internal string Description + { + get + { + return resourceManager.GetString("Description", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for EXAMPLES. + /// + internal string Examples + { + get + { + return resourceManager.GetString("Examples", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for OPTIONS. + /// + internal string Options + { + get + { + return resourceManager.GetString("Options", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for Prints help information. + /// + internal string PrintHelpDescription + { + get + { + return resourceManager.GetString("PrintHelpDescription", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for Prints version information. + /// + internal string PrintVersionDescription + { + get + { + return resourceManager.GetString("PrintVersionDescription", resourceCulture) ?? string.Empty; + } + } + + /// + /// Gets the localised string for USAGE. + /// + internal string Usage + { + get + { + return resourceManager.GetString("Usage", resourceCulture) ?? string.Empty; + } + } +} diff --git a/src/Spectre.Console.Cli/ICommandAppSettings.cs b/src/Spectre.Console.Cli/ICommandAppSettings.cs index 12fa7e14c..a1c59a7dd 100644 --- a/src/Spectre.Console.Cli/ICommandAppSettings.cs +++ b/src/Spectre.Console.Cli/ICommandAppSettings.cs @@ -5,6 +5,17 @@ namespace Spectre.Console.Cli; /// public interface ICommandAppSettings { + /// + /// Gets or sets the culture. + /// + /// + /// Text displayed by can be localised, but defaults to English. + /// Setting this property informs the resource manager which culture to use when fetching strings. + /// English will be used when a culture has not been specified (ie. this property is null) + /// or a string has not been localised for the specified culture. + /// + CultureInfo? Culture { get; set; } + /// /// Gets or sets the application name. /// diff --git a/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs b/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs index d1fba735b..f50daaec1 100644 --- a/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs +++ b/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs @@ -2,6 +2,7 @@ namespace Spectre.Console.Cli; internal sealed class CommandAppSettings : ICommandAppSettings { + public CultureInfo? Culture { get; set; } public string? ApplicationName { get; set; } public string? ApplicationVersion { get; set; } public int MaximumIndirectExamples { get; set; } @@ -19,8 +20,8 @@ internal sealed class CommandAppSettings : ICommandAppSettings public ParsingMode ParsingMode => StrictParsing ? ParsingMode.Strict : ParsingMode.Relaxed; - public Func? ExceptionHandler { get; set; } - + public Func? ExceptionHandler { get; set; } + public CommandAppSettings(ITypeRegistrar registrar) { Registrar = new TypeRegistrar(registrar); diff --git a/src/Spectre.Console.Cli/Resources/HelpProvider.Designer.cs b/src/Spectre.Console.Cli/Resources/HelpProvider.Designer.cs new file mode 100644 index 000000000..94ba7cfea --- /dev/null +++ b/src/Spectre.Console.Cli/Resources/HelpProvider.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Spectre.Console.Cli.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class HelpProvider { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal HelpProvider() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Spectre.Console.Cli.Resources.HelpProvider", typeof(HelpProvider).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to ARGUMENTS. + /// + internal static string Arguments { + get { + return ResourceManager.GetString("Arguments", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to COMMAND. + /// + internal static string Command { + get { + return ResourceManager.GetString("Command", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to COMMANDS. + /// + internal static string Commands { + get { + return ResourceManager.GetString("Commands", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to DEFAULT. + /// + internal static string Default { + get { + return ResourceManager.GetString("Default", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to DESCRIPTION. + /// + internal static string Description { + get { + return ResourceManager.GetString("Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to EXAMPLES. + /// + internal static string Examples { + get { + return ResourceManager.GetString("Examples", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OPTIONS. + /// + internal static string Options { + get { + return ResourceManager.GetString("Options", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Prints help information. + /// + internal static string PrintHelpDescription { + get { + return ResourceManager.GetString("PrintHelpDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Prints version information. + /// + internal static string PrintVersionDescription { + get { + return ResourceManager.GetString("PrintVersionDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to USAGE. + /// + internal static string Usage { + get { + return ResourceManager.GetString("Usage", resourceCulture); + } + } + } +} diff --git a/src/Spectre.Console.Cli/Resources/HelpProvider.de.resx b/src/Spectre.Console.Cli/Resources/HelpProvider.de.resx new file mode 100644 index 000000000..86e81047b --- /dev/null +++ b/src/Spectre.Console.Cli/Resources/HelpProvider.de.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ARGUMENTE + + + KOMMANDO + + + KOMMANDOS + + + STANDARDWERT + + + BESCHREIBUNG + + + BEISPIELE + + + OPTIONEN + + + Zeigt Hilfe an + + + Zeigt Versionsinformationen an + + + VERWENDUNG + + \ No newline at end of file diff --git a/src/Spectre.Console.Cli/Resources/HelpProvider.fr.resx b/src/Spectre.Console.Cli/Resources/HelpProvider.fr.resx new file mode 100644 index 000000000..1387b115a --- /dev/null +++ b/src/Spectre.Console.Cli/Resources/HelpProvider.fr.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ARGUMENTS + + + COMMANDE + + + COMMANDES + + + DÉFAUT + + + DESCRIPTION + + + EXEMPLES + + + OPTIONS + + + Affiche l'aide + + + Affiche la version + + + UTILISATION + + \ No newline at end of file diff --git a/src/Spectre.Console.Cli/Resources/HelpProvider.resx b/src/Spectre.Console.Cli/Resources/HelpProvider.resx new file mode 100644 index 000000000..3e76d0b45 --- /dev/null +++ b/src/Spectre.Console.Cli/Resources/HelpProvider.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ARGUMENTS + + + COMMAND + + + COMMANDS + + + DEFAULT + + + DESCRIPTION + + + EXAMPLES + + + OPTIONS + + + Prints help information + + + Prints version information + + + USAGE + + \ No newline at end of file diff --git a/src/Spectre.Console.Cli/Resources/HelpProvider.sv.resx b/src/Spectre.Console.Cli/Resources/HelpProvider.sv.resx new file mode 100644 index 000000000..8e9db8986 --- /dev/null +++ b/src/Spectre.Console.Cli/Resources/HelpProvider.sv.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ARGUMENT + + + KOMMANDO + + + KOMMANDON + + + STANDARD + + + BESKRIVNING + + + EXEMPEL + + + VAL + + + Skriver ut hjälpinformation + + + Skriver ut versionsnummer + + + ANVÄNDING + + \ No newline at end of file diff --git a/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj b/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj index 658dd16a8..79efdf64f 100644 --- a/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj +++ b/src/Spectre.Console.Cli/Spectre.Console.Cli.csproj @@ -31,4 +31,19 @@ + + + True + True + HelpProvider.resx + + + + + + ResXFileCodeGenerator + HelpProvider.Designer.cs + + + diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_DE.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_DE.verified.txt new file mode 100644 index 000000000..f4a58f4a1 --- /dev/null +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_DE.verified.txt @@ -0,0 +1,25 @@ +BESCHREIBUNG: +The lion command. + +VERWENDUNG: + myapp [LEGS] [OPTIONEN] [KOMMANDO] + +BEISPIELE: + myapp 20 --alive + +ARGUMENTE: + The number of teeth the lion has + [LEGS] The number of legs + +OPTIONEN: + STANDARDWERT + -h, --help Zeigt Hilfe an + -v, --version Zeigt Versionsinformationen an + -a, --alive Indicates whether or not the animal is alive + -n, --name + --agility 10 The agility between 0 and 100 + -c The number of children the lion has + -d Monday, Thursday The days the lion goes hunting + +KOMMANDOS: + giraffe The giraffe command \ No newline at end of file diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_EN.verified.txt similarity index 95% rename from test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output.verified.txt rename to test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_EN.verified.txt index 24018c08b..6f69b1f2c 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_EN.verified.txt @@ -4,6 +4,9 @@ The lion command. USAGE: myapp [LEGS] [OPTIONS] [COMMAND] +EXAMPLES: + myapp 20 --alive + ARGUMENTS: The number of teeth the lion has [LEGS] The number of legs diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_FR.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_FR.verified.txt new file mode 100644 index 000000000..9af442473 --- /dev/null +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_FR.verified.txt @@ -0,0 +1,25 @@ +DESCRIPTION: +The lion command. + +UTILISATION: + myapp [LEGS] [OPTIONS] [COMMANDE] + +EXEMPLES: + myapp 20 --alive + +ARGUMENTS: + The number of teeth the lion has + [LEGS] The number of legs + +OPTIONS: + DÉFAUT + -h, --help Affiche l'aide + -v, --version Affiche la version + -a, --alive Indicates whether or not the animal is alive + -n, --name + --agility 10 The agility between 0 and 100 + -c The number of children the lion has + -d Monday, Thursday The days the lion goes hunting + +COMMANDES: + giraffe The giraffe command \ No newline at end of file diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_SV.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_SV.verified.txt new file mode 100644 index 000000000..918755998 --- /dev/null +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default_Without_Args_Additional.Output_SV.verified.txt @@ -0,0 +1,25 @@ +BESKRIVNING: +The lion command. + +ANVÄNDING: + myapp [LEGS] [VAL] [KOMMANDO] + +EXEMPEL: + myapp 20 --alive + +ARGUMENT: + The number of teeth the lion has + [LEGS] The number of legs + +VAL: + STANDARD + -h, --help Skriver ut hjälpinformation + -v, --version Skriver ut versionsnummer + -a, --alive Indicates whether or not the animal is alive + -n, --name + --agility 10 The agility between 0 and 100 + -c The number of children the lion has + -d Monday, Thursday The days the lion goes hunting + +KOMMANDON: + giraffe The giraffe command \ No newline at end of file diff --git a/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj b/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj index e58ff863e..6f6843471 100644 --- a/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj +++ b/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj @@ -29,15 +29,4 @@ - - - $([System.String]::Copy('%(FileName)').Split('.')[0]) - %(ParentFile).cs - - - $([System.String]::Copy('%(FileName)').Split('.')[0]) - %(ParentFile).cs - - - diff --git a/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs b/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs index 0c4caf09b..a684a8a00 100644 --- a/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs +++ b/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs @@ -230,15 +230,27 @@ public Task Should_Output_Default_Command_When_Command_Has_Required_Parameters_A return Verifier.Verify(result.Output); } - [Fact] + [Theory] + [InlineData(null, "EN")] + [InlineData("", "EN")] + [InlineData("en", "EN")] + [InlineData("en-EN", "EN")] + [InlineData("fr", "FR")] + [InlineData("fr-FR", "FR")] + [InlineData("sv", "SV")] + [InlineData("sv-SE", "SV")] + [InlineData("de", "DE")] + [InlineData("de-DE", "DE")] [Expectation("Default_Without_Args_Additional")] - public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_Command_Has_Required_Parameters_And_Is_Called_Without_Args() + public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_Command_Has_Required_Parameters_And_Is_Called_Without_Args_Localised(string culture, string expectationPrefix) { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand(); fixture.Configure(configurator => { + configurator.AddExample("20", "--alive"); + configurator.SetApplicationCulture(string.IsNullOrEmpty(culture) ? null : new CultureInfo(culture)); configurator.SetApplicationName("myapp"); configurator.AddCommand("giraffe"); }); @@ -247,7 +259,9 @@ public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_C var result = fixture.Run(); // Then - return Verifier.Verify(result.Output); + var settings = new VerifySettings(); + settings.DisableRequireUniquePrefix(); + return Verifier.Verify(result.Output, settings).UseTextForParameters(expectationPrefix); } [Fact]