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

Refs #1074 - Error message "Required argument {ARGUMENT NAME} missing for command {commandName}..." #1993

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void When_subsequent_argument_with_ZeroOrOne_arity_is_not_provided_then_p
var numberOfMissingArgs =
result
.Errors
.Count(e => e.Message == LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult));
.Count(e => e.Message == LocalizationResources.Instance.RequiredArgumentMissing(command.Arguments.First(), result.CommandResult));

numberOfMissingArgs
.Should()
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ public void When_command_arguments_are_fewer_than_minimum_arity_then_an_error_is
result.Errors
.Select(e => e.Message)
.Should()
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult));
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(command.Arguments.First(), result.CommandResult));
}

[Fact]
Expand Down Expand Up @@ -1489,7 +1489,7 @@ public void When_option_arguments_are_fewer_than_minimum_arity_then_an_error_is_
result.Errors
.Select(e => e.Message)
.Should()
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(result.CommandResult.FindResultFor(option)));
.Contain(LocalizationResources.Instance.RequiredArgumentMissing(option.Argument, result.CommandResult.FindResultFor(option)));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/ResourceLocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public FakeLocalizationResources(string message)

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

public override string RequiredArgumentMissing(SymbolResult symbolResult) => message;
public override string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) => message;

public override string RequiredCommandWasNotProvided() => message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class NonWindowsOnlyFactAttribute : FactAttribute
{
public NonWindowsOnlyFactAttribute()
{
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform == Microsoft.DotNet.PlatformAbstractions.Platform.Windows)

Choose a reason for hiding this comment

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

That looks unrelated. There is a similar change elsewhere in this PR.

{
Skip = "This test requires non-Windows to run";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WindowsOnlyFactAttribute : FactAttribute
{
public WindowsOnlyFactAttribute()
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform != Microsoft.DotNet.PlatformAbstractions.Platform.Windows)
{
Skip = "This test requires Windows to run";
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/ArgumentArity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override int GetHashCode()

return ArgumentConversionResult.Failure(
argument,
symbolResult.LocalizationResources.RequiredArgumentMissing(symbolResult),
symbolResult.LocalizationResources.RequiredArgumentMissing(argument, symbolResult),
ArgumentConversionResultType.FailedMissingArgument);
}

Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Binding/ArgumentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static bool CanBeBoundFromScalarValue(this Type type)
ArgumentConversionResultType.NoArgument when conversionResult.Argument.Arity.MinimumNumberOfValues > 0 =>
ArgumentConversionResult.Failure(
conversionResult.Argument,
symbolResult.LocalizationResources.RequiredArgumentMissing(symbolResult),
symbolResult.LocalizationResources.RequiredArgumentMissing(conversionResult.Argument, symbolResult),
ArgumentConversionResultType.FailedMissingArgument),

_ => conversionResult
Expand Down
18 changes: 16 additions & 2 deletions src/System.CommandLine/LocalizationResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,25 @@ protected LocalizationResources()
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}.
/// or
/// Required argument missing for option: {0}.
/// </summary>
public virtual string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) =>
symbolResult is CommandResult
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, argument.Name, symbolResult.Token().Value)

Choose a reason for hiding this comment

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

In the development version I think this should prefer HelpName if set.

: GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, symbolResult.Token().Value);

/// <summary>
/// Interpolates values into a localized string similar to
/// Required argument {0} missing for command: {1}.
/// or
/// Required argument missing for option: {0}.
/// </summary>
public virtual string RequiredArgumentMissing(SymbolResult symbolResult) =>
symbolResult is CommandResult
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, symbolResult.Token().Value)
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, "(unknown)", symbolResult.Token().Value)
: GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, symbolResult.Token().Value);
Comment on lines 104 to 107

Choose a reason for hiding this comment

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

Because #2041 made LocalizationResources internal, you can just delete this overload. Then there won't be an "(unknown)" string that might have to be localised.


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Properties/Resources.Designer.cs

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

2 changes: 1 addition & 1 deletion src/System.CommandLine/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{1}'.</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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{1}'.</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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{1}'.</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 @@ -33,8 +33,8 @@
<note />
</trans-unit>
<trans-unit id="CommandRequiredArgumentMissing">
<source>Required argument missing for command: '{0}'.</source>
<target state="new">Required argument missing for command: '{0}'.</target>
<source>Required argument '{0}' missing for command: '{1}'.</source>
<target state="new">Required argument '{0}' missing for command: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="DirectoryDoesNotExist">
Expand Down
1 change: 1 addition & 0 deletions src/System.CommandLine/System.CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

<ItemGroup>
<InternalsVisibleTo Include="System.CommandLine.NamingConventionBinder" />
<InternalsVisibleTo Include="System.CommandLine.Tests" />
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to avoid making internals visible to tests.

</ItemGroup>

</Project>