Skip to content

Commit

Permalink
Fixed issue when ARgumentRequiresOtherArgumentsCertification ignored …
Browse files Browse the repository at this point in the history
…default argument values

Fixes #48
  • Loading branch information
j-maly committed Aug 12, 2017
1 parent 1a8ecd5 commit e891473
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<RootNamespace>CommandLineParser</RootNamespace>
<Version>3.0.13</Version>
<AssemblyVersion>3.0.13.0</AssemblyVersion>
<FileVersion>3.0.13.0</FileVersion>
<Version>3.0.14</Version>
<AssemblyVersion>3.0.14.0</AssemblyVersion>
<FileVersion>3.0.14.0</FileVersion>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>CommandLineArgumentsParser.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -106,7 +111,7 @@ public class ArgumentRequiresOtherArgumentsCertificationAttribute : ArgumentCert
/// <param name="argumentsRequiredForMainArgument">arguments required by <paramref name="mainArgument"/> - names of the
/// arguments separated by commas, semicolons or '|' character</param>
public ArgumentRequiresOtherArgumentsCertificationAttribute(string mainArgument, string argumentsRequiredForMainArgument)
: base(typeof(DistinctGroupsCertification), mainArgument, argumentsRequiredForMainArgument)
: base(typeof(ArgumentRequiresOtherArgumentsCertification), mainArgument, argumentsRequiredForMainArgument)
{
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/Tests/Tests.GroupCertifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e891473

Please sign in to comment.