mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add error for non-scalar parameters bound without any values (#71)
This commit is contained in:
@@ -894,6 +894,31 @@ namespace CliFx.Tests
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Scalar_properties_annotated_as_parameter_requires_input()
|
||||
{
|
||||
// Arrange
|
||||
var input = new CommandInputBuilder()
|
||||
.Build();
|
||||
|
||||
// Act & assert
|
||||
var ex = Assert.Throws<CliFxException>(() => CommandHelper.ResolveCommand<ParametersCommand>(input));
|
||||
_output.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NonScalar_properties_annotated_as_parameter_requires_input()
|
||||
{
|
||||
// Arrange
|
||||
var input = new CommandInputBuilder()
|
||||
.AddParameter("foo")
|
||||
.AddParameter("bar")
|
||||
.Build();
|
||||
|
||||
var ex = Assert.Throws<CliFxException>(() => CommandHelper.ResolveCommand<ParametersCommand>(input));
|
||||
_output.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Property_annotated_as_parameter_must_always_be_bound_to_some_value()
|
||||
{
|
||||
|
||||
@@ -103,7 +103,10 @@ namespace CliFx.Domain
|
||||
|
||||
if (nonScalarParameter != null)
|
||||
{
|
||||
// TODO: Should it verify that at least one value is passed?
|
||||
// Verify that we have at least one value
|
||||
if(!parameterInputs.Skip(scalarParameters.Length).Any())
|
||||
throw CliFxException.ParameterNotSet(nonScalarParameter);
|
||||
|
||||
var nonScalarValues = parameterInputs
|
||||
.Skip(scalarParameters.Length)
|
||||
.Select(p => p.Value)
|
||||
|
||||
Reference in New Issue
Block a user