Skip to content

Commit 34a1981

Browse files
committed
Refs dotnet#1074 - Instead of "Required argument missing for command: {commandname}", should provide "Required argument {argumentname} missing for command: {commandname}" for better clarity as to which required argument is missing.
1 parent c75c74b commit 34a1981

24 files changed

+53
-38
lines changed

src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void When_there_are_not_enough_tokens_for_all_arguments_then_the_correct_
307307
var numberOfMissingArgs =
308308
result
309309
.Errors
310-
.Count(e => e.Message == LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult));
310+
.Count(e => e.Message == LocalizationResources.Instance.RequiredArgumentMissing(command.Arguments.First(), result.CommandResult));
311311

312312
numberOfMissingArgs
313313
.Should()

src/System.CommandLine.Tests/ParserTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ public void When_command_arguments_are_fewer_than_minimum_arity_then_an_error_is
14011401
result.Errors
14021402
.Select(e => e.Message)
14031403
.Should()
1404-
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult));
1404+
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(command.Arguments.First(), result.CommandResult));
14051405
}
14061406

14071407
[Fact]
@@ -1489,7 +1489,7 @@ public void When_option_arguments_are_fewer_than_minimum_arity_then_an_error_is_
14891489
result.Errors
14901490
.Select(e => e.Message)
14911491
.Should()
1492-
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult.FindResultFor(option)));
1492+
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(option.Argument, result.CommandResult.FindResultFor(option)));
14931493
}
14941494

14951495
[Fact]

src/System.CommandLine.Tests/ResourceLocalizationTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public FakeLocalizationResources(string message)
6262

6363
public override string FileDoesNotExist(string filePath) => message;
6464

65-
public override string RequiredArgumentMissing(SymbolResult symbolResult) => message;
65+
public override string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) => message;
6666

6767
public override string RequiredCommandWasNotProvided() => message;
6868

src/System.CommandLine.Tests/Utility/NonWindowsOnlyFactAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class NonWindowsOnlyFactAttribute : FactAttribute
1010
{
1111
public NonWindowsOnlyFactAttribute()
1212
{
13-
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
13+
if (RuntimeEnvironment.OperatingSystemPlatform == Microsoft.DotNet.PlatformAbstractions.Platform.Windows)
1414
{
1515
Skip = "This test requires non-Windows to run";
1616
}

src/System.CommandLine.Tests/Utility/WindowsOnlyFactAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class WindowsOnlyFactAttribute : FactAttribute
1010
{
1111
public WindowsOnlyFactAttribute()
1212
{
13-
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
13+
if (RuntimeEnvironment.OperatingSystemPlatform != Microsoft.DotNet.PlatformAbstractions.Platform.Windows)
1414
{
1515
Skip = "This test requires Windows to run";
1616
}

src/System.CommandLine/ArgumentArity.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public override int GetHashCode()
9595

9696
return ArgumentConversionResult.Failure(
9797
argument,
98-
symbolResult.LocalizationResources.RequiredArgumentMissing(symbolResult),
98+
symbolResult.LocalizationResources.RequiredArgumentMissing(argument, symbolResult),
9999
ArgumentConversionResultType.FailedMissingArgument);
100100
}
101101

src/System.CommandLine/Binding/ArgumentConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ internal static ArgumentConversionResult ConvertIfNeeded(
195195
ArgumentConversionResultType.NoArgument when conversionResult.Argument.Arity.MinimumNumberOfValues > 0 =>
196196
ArgumentConversionResult.Failure(
197197
conversionResult.Argument,
198-
symbolResult.LocalizationResources.RequiredArgumentMissing(symbolResult),
198+
symbolResult.LocalizationResources.RequiredArgumentMissing(conversionResult.Argument, symbolResult),
199199
ArgumentConversionResultType.FailedMissingArgument),
200200

201201
_ => conversionResult

src/System.CommandLine/LocalizationResources.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,25 @@ public virtual string InvalidCharactersInFileName(char invalidChar) =>
8585
GetResourceString(Properties.Resources.InvalidCharactersInFileName, invalidChar);
8686

8787
/// <summary>
88-
/// Interpolates values into a localized string similar to Required argument missing for command: {0}.
88+
/// Interpolates values into a localized string similar to
89+
/// Required argument {0} missing for command: {1}.
90+
/// or
91+
/// Required argument missing for option: {0}.
92+
/// </summary>
93+
public virtual string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) =>
94+
symbolResult is CommandResult
95+
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, argument.Name, symbolResult.Token().Value)
96+
: GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, symbolResult.Token().Value);
97+
98+
/// <summary>
99+
/// Interpolates values into a localized string similar to
100+
/// Required argument {0} missing for command: {1}.
101+
/// or
102+
/// Required argument missing for option: {0}.
89103
/// </summary>
90104
public virtual string RequiredArgumentMissing(SymbolResult symbolResult) =>
91105
symbolResult is CommandResult
92-
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, symbolResult.Token().Value)
106+
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, "(unknown)", symbolResult.Token().Value)
93107
: GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, symbolResult.Token().Value);
94108

95109
/// <summary>

src/System.CommandLine/Properties/Resources.Designer.cs

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

src/System.CommandLine/Properties/Resources.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<value>Character not allowed in a path: '{0}'.</value>
149149
</data>
150150
<data name="CommandRequiredArgumentMissing" xml:space="preserve">
151-
<value>Required argument missing for command: '{0}'.</value>
151+
<value>Required argument '{0}' missing for command: '{1}'.</value>
152152
</data>
153153
<data name="OptionRequiredArgumentMissing" xml:space="preserve">
154154
<value>Required argument missing for option: '{0}'.</value>

src/System.CommandLine/Properties/xlf/Resources.cs.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.de.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.es.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.fr.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.it.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.ja.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.ko.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.pl.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.ru.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.tr.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<note />
3434
</trans-unit>
3535
<trans-unit id="CommandRequiredArgumentMissing">
36-
<source>Required argument missing for command: '{0}'.</source>
37-
<target state="new">Required argument missing for command: '{0}'.</target>
36+
<source>Required argument '{0}' missing for command: '{1}'.</source>
37+
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
3838
<note />
3939
</trans-unit>
4040
<trans-unit id="DirectoryDoesNotExist">

src/System.CommandLine/System.CommandLine.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
<ItemGroup>
5454
<InternalsVisibleTo Include="System.CommandLine.NamingConventionBinder" />
55+
<InternalsVisibleTo Include="System.CommandLine.Tests" />
5556
</ItemGroup>
5657

5758
</Project>

0 commit comments

Comments
 (0)