Skip to content
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
5 changes: 3 additions & 2 deletions src/System.CommandLine.Tests/LocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace System.CommandLine.Tests
public class LocalizationTests
{
private const string CommandName = "the-command";
private const string ArgumentName = "arg";

[Theory]
[InlineData("es", $"Falta el argumento requerido para el comando: '{CommandName}'.")]
[InlineData("en-US", $"Required argument missing for command: '{CommandName}'.")]
[InlineData("es", $"Falta el argumento requerido '{ArgumentName}' para el comando: '{CommandName}'.")]
[InlineData("en-US", $"Required argument '{ArgumentName}' missing for command: '{CommandName}'.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is probably not sufficient to test this change. It would be helpful to see additional testing where a command has multiple Argument<T> objects.

This kind of test isn't really about localization. Maybe add a test alongside this one for this case:

[Fact]
public void When_command_arguments_are_fewer_than_minimum_arity_then_an_error_is_returned()
{
var command = new Command("the-command")
{
new Argument<string[]>("arg")
{
Arity = new ArgumentArity(2, 3)
}
};
var result = command.Parse("1");
result.Errors
.Select(e => e.Message)
.Should()
.Contain(LocalizationResources.RequiredArgumentMissing(result.GetResult(command.Arguments[0])));
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I've added a test for multiple missing args - is that what you were looking for?

public void ErrorMessages_AreLocalized(string cultureName, string expectedMessage)
{
CultureInfo uiCultureBefore = CultureInfo.CurrentUICulture;
Expand Down
23 changes: 23 additions & 0 deletions src/System.CommandLine.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,29 @@ public void When_option_arguments_are_greater_than_maximum_arity_then_an_error_i
.Contain(LocalizationResources.UnrecognizedCommandOrArgument("4"));
}

[Fact]
public void When_required_argument_is_missing_then_an_error_is_returned()
{
var command = new Command("the-command")
{
new Argument<string>("arg0"),
new Argument<string>("missing-arg1"),
new Argument<string>("missing-arg2")
};

var result = command.Parse("value-for-arg1");

result.Errors
.Select(e => e.Message)
.Should()
.BeEquivalentTo(
// "Required argument 'missing-arg1' missing for command: 'the-command'."
LocalizationResources.RequiredArgumentMissing(result.GetResult(command.Arguments[1])),
// "Required argument 'missing-arg2' missing for command: 'the-command'."
LocalizationResources.RequiredArgumentMissing(result.GetResult(command.Arguments[2]))
);
}

[Fact]
public void Tokens_are_not_split_if_the_part_before_the_delimiter_is_not_an_option()
{
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/LocalizationResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ internal static string InvalidCharactersInFileName(char invalidChar) =>
GetResourceString(Properties.Resources.InvalidCharactersInFileName, invalidChar);

/// <summary>
/// Interpolates values into a localized string similar to Required argument missing for command: {0}.
/// Interpolates values into a localized string similar to Required argument '{0}' missing for command: '{1}'.
/// </summary>
internal static string RequiredArgumentMissing(ArgumentResult argumentResult) =>
argumentResult.Parent is CommandResult commandResult
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, commandResult.IdentifierToken.Value)
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, argumentResult.Argument.Name, commandResult.IdentifierToken.Value)
: RequiredArgumentMissing((OptionResult)argumentResult.Parent!);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<value>Character not allowed in a path: '{0}'.</value>
</data>
<data name="CommandRequiredArgumentMissing" xml:space="preserve">
<value>Required argument missing for command: '{0}'.</value>
<value>Required argument '{0}' missing for command: '{1}'.</value>
</data>
<data name="OptionRequiredArgumentMissing" xml:space="preserve">
<value>Required argument missing for option: '{0}'.</value>
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Chybí povinný argument pro příkaz: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Chybí povinný argument '{0}' pro příkaz: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Ein erforderliches Argument fehlt für den Befehl: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Ein erforderliches Argument '{0}' fehlt für den Befehl: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Falta el argumento requerido para el comando: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Falta el argumento requerido '{0}' para el comando: '{1}'.</target>
<note></note>
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.fi.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Pakollinen argumentti puuttuu komennolta: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Pakollinen argumentti '{0}' puuttuu komennolta: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Argument obligatoire manquant pour la commande : '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Argument obligatoire '{0}' manquant pour la commande : '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Manca l'argomento obbligatorio per il comando: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Manca l'argomento obbligatorio '{0}' per il comando: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">必要な引数がコマンドにありません: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">必要な引数 '{0}' がコマンド '{1}' にありません。</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">명령 '{0}'에 대한 필수 인수가 없습니다.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">명령 '{1}'에 대한 필수 인수 '{0}'이(가) 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Brakuje argumentu wymaganego polecenia: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Brakuje argumentu wymaganego '{0}' polecenia: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Argumento obrigatório ausente para o comando: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Argumento obrigatório '{0}' ausente para o comando: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Отсутствует обязательный аргумент для команды: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Отсутствует обязательный аргумент '{0}' для команды: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">Komut için gerekli bağımsız değişken eksik: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">Komut '{1}' için gerekli bağımsız değişken '{0}' eksik.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">命令缺少所需参数: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">命令 '{1}' 缺少所需参数 '{0}'</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="translated">命令遺漏必要引數: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="translated">命令 '{1}' 遺漏必要引數 '{0}'</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down