From 34a198112043fd12f0caf188b5f3b63a693da39f Mon Sep 17 00:00:00 2001 From: Rick Drizin Date: Tue, 13 Dec 2022 21:27:34 -0500 Subject: [PATCH] Refs #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. --- .../ParserTests.MultipleArguments.cs | 2 +- src/System.CommandLine.Tests/ParserTests.cs | 4 ++-- .../ResourceLocalizationTests.cs | 2 +- .../Utility/NonWindowsOnlyFactAttribute.cs | 2 +- .../Utility/WindowsOnlyFactAttribute.cs | 2 +- src/System.CommandLine/ArgumentArity.cs | 2 +- .../Binding/ArgumentConverter.cs | 2 +- .../LocalizationResources.cs | 18 ++++++++++++++++-- .../Properties/Resources.Designer.cs | 2 +- .../Properties/Resources.resx | 2 +- .../Properties/xlf/Resources.cs.xlf | 4 ++-- .../Properties/xlf/Resources.de.xlf | 4 ++-- .../Properties/xlf/Resources.es.xlf | 4 ++-- .../Properties/xlf/Resources.fr.xlf | 4 ++-- .../Properties/xlf/Resources.it.xlf | 4 ++-- .../Properties/xlf/Resources.ja.xlf | 4 ++-- .../Properties/xlf/Resources.ko.xlf | 4 ++-- .../Properties/xlf/Resources.pl.xlf | 4 ++-- .../Properties/xlf/Resources.pt-BR.xlf | 4 ++-- .../Properties/xlf/Resources.ru.xlf | 4 ++-- .../Properties/xlf/Resources.tr.xlf | 4 ++-- .../Properties/xlf/Resources.zh-Hans.xlf | 4 ++-- .../Properties/xlf/Resources.zh-Hant.xlf | 4 ++-- .../System.CommandLine.csproj | 1 + 24 files changed, 53 insertions(+), 38 deletions(-) diff --git a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs index 331f8d6515..f2e28b791f 100644 --- a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs +++ b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs @@ -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() diff --git a/src/System.CommandLine.Tests/ParserTests.cs b/src/System.CommandLine.Tests/ParserTests.cs index 103a10f646..e36dba3164 100644 --- a/src/System.CommandLine.Tests/ParserTests.cs +++ b/src/System.CommandLine.Tests/ParserTests.cs @@ -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] @@ -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] diff --git a/src/System.CommandLine.Tests/ResourceLocalizationTests.cs b/src/System.CommandLine.Tests/ResourceLocalizationTests.cs index a22841ec3e..3a20a362f3 100644 --- a/src/System.CommandLine.Tests/ResourceLocalizationTests.cs +++ b/src/System.CommandLine.Tests/ResourceLocalizationTests.cs @@ -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; diff --git a/src/System.CommandLine.Tests/Utility/NonWindowsOnlyFactAttribute.cs b/src/System.CommandLine.Tests/Utility/NonWindowsOnlyFactAttribute.cs index 4b1e99d3e5..201e300f15 100644 --- a/src/System.CommandLine.Tests/Utility/NonWindowsOnlyFactAttribute.cs +++ b/src/System.CommandLine.Tests/Utility/NonWindowsOnlyFactAttribute.cs @@ -10,7 +10,7 @@ public class NonWindowsOnlyFactAttribute : FactAttribute { public NonWindowsOnlyFactAttribute() { - if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Microsoft.DotNet.PlatformAbstractions.Platform.Windows) { Skip = "This test requires non-Windows to run"; } diff --git a/src/System.CommandLine.Tests/Utility/WindowsOnlyFactAttribute.cs b/src/System.CommandLine.Tests/Utility/WindowsOnlyFactAttribute.cs index ab389624a9..3ed855770f 100644 --- a/src/System.CommandLine.Tests/Utility/WindowsOnlyFactAttribute.cs +++ b/src/System.CommandLine.Tests/Utility/WindowsOnlyFactAttribute.cs @@ -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"; } diff --git a/src/System.CommandLine/ArgumentArity.cs b/src/System.CommandLine/ArgumentArity.cs index c0153fc86e..8499a35dd2 100644 --- a/src/System.CommandLine/ArgumentArity.cs +++ b/src/System.CommandLine/ArgumentArity.cs @@ -95,7 +95,7 @@ public override int GetHashCode() return ArgumentConversionResult.Failure( argument, - symbolResult.LocalizationResources.RequiredArgumentMissing(symbolResult), + symbolResult.LocalizationResources.RequiredArgumentMissing(argument, symbolResult), ArgumentConversionResultType.FailedMissingArgument); } diff --git a/src/System.CommandLine/Binding/ArgumentConverter.cs b/src/System.CommandLine/Binding/ArgumentConverter.cs index bc86831770..7cbb2a1bd1 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.cs @@ -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 diff --git a/src/System.CommandLine/LocalizationResources.cs b/src/System.CommandLine/LocalizationResources.cs index 0107ce06fe..e80bed9f1a 100644 --- a/src/System.CommandLine/LocalizationResources.cs +++ b/src/System.CommandLine/LocalizationResources.cs @@ -85,11 +85,25 @@ protected LocalizationResources() GetResourceString(Properties.Resources.InvalidCharactersInFileName, invalidChar); /// - /// 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}. + /// + public virtual string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) => + symbolResult is CommandResult + ? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, argument.Name, symbolResult.Token().Value) + : GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, symbolResult.Token().Value); + + /// + /// Interpolates values into a localized string similar to + /// Required argument {0} missing for command: {1}. + /// or + /// Required argument missing for option: {0}. /// 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); /// diff --git a/src/System.CommandLine/Properties/Resources.Designer.cs b/src/System.CommandLine/Properties/Resources.Designer.cs index ddb11c322f..19ae3d9529 100644 --- a/src/System.CommandLine/Properties/Resources.Designer.cs +++ b/src/System.CommandLine/Properties/Resources.Designer.cs @@ -115,7 +115,7 @@ internal class Resources { } /// - /// Looks up a localized string similar to Required argument missing for command: '{0}'.. + /// Looks up a localized string similar to Required argument '{0}' missing for command: '{1}'.. /// internal static string CommandRequiredArgumentMissing { get { diff --git a/src/System.CommandLine/Properties/Resources.resx b/src/System.CommandLine/Properties/Resources.resx index f0b101ebba..052fa30b83 100644 --- a/src/System.CommandLine/Properties/Resources.resx +++ b/src/System.CommandLine/Properties/Resources.resx @@ -148,7 +148,7 @@ Character not allowed in a path: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. Required argument missing for option: '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.cs.xlf b/src/System.CommandLine/Properties/xlf/Resources.cs.xlf index 86c81955a1..9ca5d0c7a1 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.cs.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.cs.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.de.xlf b/src/System.CommandLine/Properties/xlf/Resources.de.xlf index e47d4bc1ee..f125d18efd 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.de.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.de.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.es.xlf b/src/System.CommandLine/Properties/xlf/Resources.es.xlf index 2e85b00d2f..3ef03ab2ba 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.es.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.es.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.fr.xlf b/src/System.CommandLine/Properties/xlf/Resources.fr.xlf index e8afe2a034..99b3695a72 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.fr.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.fr.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.it.xlf b/src/System.CommandLine/Properties/xlf/Resources.it.xlf index 040135ce41..e4e3649be3 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.it.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.it.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ja.xlf b/src/System.CommandLine/Properties/xlf/Resources.ja.xlf index aa9c63dce5..c4e10dc9cc 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ja.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ja.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ko.xlf b/src/System.CommandLine/Properties/xlf/Resources.ko.xlf index f5a4950dca..6b13db2c23 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ko.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ko.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.pl.xlf b/src/System.CommandLine/Properties/xlf/Resources.pl.xlf index b5cf7fd3f0..2790f02c95 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.pl.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.pl.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf b/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf index 8f7e7af0d2..87b0509f1e 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ru.xlf b/src/System.CommandLine/Properties/xlf/Resources.ru.xlf index 6a8b8128f5..882cb876fe 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ru.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ru.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.tr.xlf b/src/System.CommandLine/Properties/xlf/Resources.tr.xlf index c43d076b4d..971288b3e6 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.tr.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.tr.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf b/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf index ca955abebc..e80d1963ae 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf b/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf index 3ceabfdb3d..132a4da0f6 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf @@ -33,8 +33,8 @@ - Required argument missing for command: '{0}'. - Required argument missing for command: '{0}'. + Required argument '{0}' missing for command: '{1}'. + Required argument '{0}' missing for command: '{1}'. diff --git a/src/System.CommandLine/System.CommandLine.csproj b/src/System.CommandLine/System.CommandLine.csproj index 05d2847639..81a642d370 100644 --- a/src/System.CommandLine/System.CommandLine.csproj +++ b/src/System.CommandLine/System.CommandLine.csproj @@ -52,6 +52,7 @@ +