diff --git a/src/CLIParser/ArgumentMetadata.cs b/src/CLIParser/ArgumentMetadata.cs index e9e6a6c..1cfac07 100644 --- a/src/CLIParser/ArgumentMetadata.cs +++ b/src/CLIParser/ArgumentMetadata.cs @@ -589,6 +589,21 @@ void IArgumentMetadataHelper.Check() if (Default != null) Helper.TestValue(Default); } + bool checkParam(string stringToTest) + { + bool result = false; + switch (Type) + { + case ArgumentType.KeyValue: + result = stringToTest.StartsWith(Helper.StartWith) || (!string.IsNullOrEmpty(Helper.ShortStartWith) ? stringToTest.StartsWith(Helper.ShortStartWith) : false); + break; + default: + result = stringToTest == Helper.StartWith || (!string.IsNullOrEmpty(Helper.ShortStartWith) ? stringToTest == Helper.ShortStartWith : false); + break; + } + return result; + } + IArgumentMetadataParsed IArgumentMetadataHelper.Parse(IList args) { for (int i = 0; i < args.Count; i++) @@ -606,7 +621,7 @@ IArgumentMetadataParsed IArgumentMetadataHelper.Parse(IList args) args.RemoveAt(i); return parsedData; } - else if (stringToTest.StartsWith(Helper.StartWith) || (!string.IsNullOrEmpty(Helper.ShortStartWith) ? stringToTest.StartsWith(Helper.ShortStartWith) : false)) + else if (checkParam(stringToTest)) { ArgumentMetadataParsed parsedData = new ArgumentMetadataParsed(this) { diff --git a/src/CLIParser/CLIParser.cs b/src/CLIParser/CLIParser.cs index 564a243..adedb36 100644 --- a/src/CLIParser/CLIParser.cs +++ b/src/CLIParser/CLIParser.cs @@ -167,7 +167,7 @@ public static IEnumerable Override(this IEnumerable /// Filter the for existing /// - /// Arguments to test using the list prepared using + /// Arguments to test using the list prepared using /// A filtered list of public static IEnumerable Exists(this IEnumerable args) { @@ -186,7 +186,7 @@ public static IEnumerable Exists(this IEnumerable /// Check the for existing /// - /// Arguments to test using the list prepared using + /// Arguments to test using the list prepared using /// Argument name to search /// true if the the argument with name exist public static bool Exist(this IEnumerable args, string name) @@ -202,7 +202,7 @@ public static bool Exist(this IEnumerable args, string /// /// Filter the for non existing /// - /// Arguments to test using the list prepared using + /// Arguments to test using the list prepared using /// A filtered list of public static IEnumerable NotExists(this IEnumerable args) { @@ -561,7 +561,7 @@ public int PaddingFromArguments() /// Returns the help information /// /// The width of the help to write - /// A + /// A with help information public string HelpInfo(int? width = null) { int newWidth = Console.WindowWidth; diff --git a/src/CLIParser/CLIParser.csproj b/src/CLIParser/CLIParser.csproj index 00f512b..cd0d2a3 100644 --- a/src/CLIParser/CLIParser.csproj +++ b/src/CLIParser/CLIParser.csproj @@ -8,7 +8,7 @@ MASES s.r.l. MASES s.r.l. MASES s.r.l. - 2.1.1.0 + 2.1.2.0 CLIParser true net461;netcoreapp3.1;net5.0;net5.0-windows diff --git a/tests/CLIParserTest/CLIParserTest.csproj b/tests/CLIParserTest/CLIParserTest.csproj index 9ce270d..aa0a851 100644 --- a/tests/CLIParserTest/CLIParserTest.csproj +++ b/tests/CLIParserTest/CLIParserTest.csproj @@ -9,7 +9,7 @@ Copyright © MASES s.r.l. 2021 MASES s.r.l. MASES s.r.l. - 2.1.1.0 + 2.1.2.0 net461;netcoreapp3.1;net5.0;net5.0-windows ..\..\bin\ diff --git a/tests/CLIParserTest/Program.cs b/tests/CLIParserTest/Program.cs index c0a278b..9539bd3 100644 --- a/tests/CLIParserTest/Program.cs +++ b/tests/CLIParserTest/Program.cs @@ -80,6 +80,16 @@ static void Main(string[] args) Name = "myval", Type = ArgumentType.Single, }); + parser.Add(new ArgumentMetadata(parser) + { + Name = "MyParam", + Type = ArgumentType.Double, + }); + parser.Add(new ArgumentMetadata(parser) + { + Name = "MyParam2", + Type = ArgumentType.Double, + }); var result = parser.Parse(args); diff --git a/tests/CLIParserTest/Properties/launchSettings.json b/tests/CLIParserTest/Properties/launchSettings.json index ab943b4..47a615c 100644 --- a/tests/CLIParserTest/Properties/launchSettings.json +++ b/tests/CLIParserTest/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CLIParserTest": { "commandName": "Project", - "commandLineArgs": "-enum \"Second,Third\" -range 9 -multivalue \"qui:quo:qua\" -tst true -tst false @MyFile ???" + "commandLineArgs": "-MyParam2 pippo -enum \"Second,Third\" -range 9 -multivalue \"qui:quo:qua\" -tst true -tst false @MyFile ???" } } } \ No newline at end of file