Skip to content

Commit

Permalink
Merge pull request #4139 from EdLichtman/develop
Browse files Browse the repository at this point in the history
GH-4128: Fix Inconsistent determination of positional Argument when using context.Arguments versus context.Argument
  • Loading branch information
augustoproiete authored Apr 22, 2023
2 parents e2ccd15 + 8d8d963 commit b55239f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Cake.Common/ArgumentAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static T Argument<T>(this ICakeContext context, string name)
throw new ArgumentNullException(nameof(context));
}

var value = context.Arguments.GetArguments(name).FirstOrDefault();
var value = context.Arguments.GetArguments(name).LastOrDefault();
if (value == null)
{
const string format = "Argument '{0}' was not set.";
Expand Down Expand Up @@ -248,7 +248,7 @@ public static T Argument<T>(this ICakeContext context, string name, T defaultVal
throw new ArgumentNullException(nameof(context));
}

var value = context.Arguments.GetArguments(name)?.FirstOrDefault();
var value = context.Arguments.GetArguments(name)?.LastOrDefault();
return value == null
? defaultValue
: Convert<T>(value);
Expand Down
28 changes: 20 additions & 8 deletions tests/integration/Cake.Common/ArgumentAliases.cake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ Task("Cake.Common.ArgumentAliases.Argument.WithDefaultValue")
Assert.Equal("foo", arg);
});

Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments")
Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.GetsLastValue")
.Does(() =>
{
// Given, When
var arg = Argument<string>("multipleargs");

// Then
Assert.Equal("b", arg);
});


Task("Cake.Common.ArgumentAliases.Arguments.MultipleArguments")
.Does(() =>
{

Expand All @@ -53,7 +64,7 @@ Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments")
Assert.Equal(new[] { "a", "b" }, arg);
});

Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithSingleDefaultValue")
Task("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithSingleDefaultValue")
.Does(() =>
{
// Given
Expand All @@ -66,7 +77,7 @@ Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithSingleDefaultVa
Assert.Equal(expect, arg);
});

Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithMultipleDefaultValue")
Task("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithMultipleDefaultValue")
.Does(() =>
{
// Given
Expand All @@ -79,7 +90,7 @@ Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithMultipleDefault
Assert.Equal(expect, arg);
});

Task("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithLazyDefaultValue")
Task("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithLazyDefaultValue")
.Does(() =>
{
// Given
Expand Down Expand Up @@ -145,10 +156,11 @@ Task("Cake.Common.ArgumentAliases")
.IsDependentOn("Cake.Common.ArgumentAliases.HasArgument.ThatDoNotExist")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.WithDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.MultipleArguments")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithSingleDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithMultipleDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.MultipleArguments.WithLazyDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.MultipleArguments.GetsLastValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Arguments.MultipleArguments")
.IsDependentOn("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithSingleDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithMultipleDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Arguments.MultipleArguments.WithLazyDefaultValue")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.DirectoryPathArgument")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.FilePathArgument")
.IsDependentOn("Cake.Common.ArgumentAliases.Argument.DotNetVerbosityArgument")
Expand Down

0 comments on commit b55239f

Please sign in to comment.