diff --git a/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj b/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj index beafe0a..7c289af 100644 --- a/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj +++ b/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj @@ -20,9 +20,9 @@ false false CommandLineParser - 3.0.13 - 3.0.13.0 - 3.0.13.0 + 3.0.14 + 3.0.14.0 + 3.0.14.0 True CommandLineArgumentsParser.pfx diff --git a/src/CommandLineArgumentsParser/Validation/ArgumentRequiresOtherArgumentsCertification.cs b/src/CommandLineArgumentsParser/Validation/ArgumentRequiresOtherArgumentsCertification.cs index 21db58b..9b3dc33 100644 --- a/src/CommandLineArgumentsParser/Validation/ArgumentRequiresOtherArgumentsCertification.cs +++ b/src/CommandLineArgumentsParser/Validation/ArgumentRequiresOtherArgumentsCertification.cs @@ -80,7 +80,12 @@ public override void Certify(CommandLineParser parser) { if (!requiredArgument.Parsed) { - throw new MandatoryArgumentNotSetException(String.Format(Messages.EXC_GROUP_DISTINCT, _mainArgumentString, _argumentsRequiredForMainArgumentString), requiredArgument.Name); + var withDefaultValue = requiredArgument as IArgumentWithDefaultValue; + if (withDefaultValue?.DefaultValue != null) + { + continue; + } + throw new MandatoryArgumentNotSetException(String.Format(Messages.EXC_GROUP_ARGUMENTS_REQUIRED_BY_ANOTHER_ARGUMENT, _mainArgumentString, _argumentsRequiredForMainArgumentString), requiredArgument.Name); } } } @@ -106,7 +111,7 @@ public class ArgumentRequiresOtherArgumentsCertificationAttribute : ArgumentCert /// arguments required by - names of the /// arguments separated by commas, semicolons or '|' character public ArgumentRequiresOtherArgumentsCertificationAttribute(string mainArgument, string argumentsRequiredForMainArgument) - : base(typeof(DistinctGroupsCertification), mainArgument, argumentsRequiredForMainArgument) + : base(typeof(ArgumentRequiresOtherArgumentsCertification), mainArgument, argumentsRequiredForMainArgument) { } } diff --git a/src/Tests/Tests.GroupCertifications.cs b/src/Tests/Tests.GroupCertifications.cs index a96e69d..c5c6fa1 100644 --- a/src/Tests/Tests.GroupCertifications.cs +++ b/src/Tests/Tests.GroupCertifications.cs @@ -406,7 +406,46 @@ public void ArgumentRequiresOtherArgumentsCertification_shouldPass_whenMainArgum string[] args = new[] { "-m" }; commandLineParser.ParseCommandLine(args); Assert.Equal(true, commandLineParser.ParsingSucceeded); + } + + [DistinctGroupsCertification("s", "h,p")] + [ArgumentRequiresOtherArgumentsCertification("h", "p,c,i,o")] + internal class TestDefaultValues + { + [ValueArgument(typeof(string), 's', "serverName", Description = "The friendly name given to the rabbit server connection.")] + public string ServerName { get; set; } + + [ValueArgument(typeof(string), 'h', "hostName", Description = "The fully qualified host name of the rabbit server.")] + public string ServerHostName { get; set; } + + [ValueArgument(typeof(int), 'p', "port", Description = "The port that should be used to connect to the rabbit server.", DefaultValue = 5672)] + public int Port { get; set; } + + [RegexValueArgument('c', "credentials", ".*", + Description = + "The username and password that needs to be used to connect to the rabbit server. This needs to be in the format username|password")] + public string Credentials { get; set; } + + [ValueArgument(typeof(string), 'v', "virtualHost", Description = "The virtual host on the rabbit server that contains the scribe exchanges.", DefaultValue = "v.pds.ren.scribe")] + public string ScribeVirtualHost { get; set; } + + [ValueArgument(typeof(string), 'i', "input", Description = "The scribe input exchange.", DefaultValue = "e.pds.tools.scribe.input")] + public string ScribeInputExchange { get; set; } + [ValueArgument(typeof(string), 'o', "output", Description = "The scribe output exchange.", DefaultValue = "e.pds.tools.scribe.output")] + public string ScribeOutputExchange { get; set; } + } + + [Fact] + public void ArgumentRequiresOtherArgumentsCertification_shouldPass_whenDefaultValuesAreThere() + { + var commandLineParser = new CommandLineParser.CommandLineParser(); + var parsingTarget = new TestDefaultValues(); + commandLineParser.ExtractArgumentAttributes(parsingTarget); + + string[] args = { "-h", "dwerecrq01.hq.bn-corp.com", "-c", "renscribeui@Lithium3" }; + commandLineParser.ParseCommandLine(args); + Assert.Equal(true, commandLineParser.ParsingSucceeded); } #endregion