diff --git a/src/Cake.Core/Configuration/CakeConfigurationProvider.cs b/src/Cake.Core/Configuration/CakeConfigurationProvider.cs
index 4bd756ccc0..15af1708c4 100644
--- a/src/Cake.Core/Configuration/CakeConfigurationProvider.cs
+++ b/src/Cake.Core/Configuration/CakeConfigurationProvider.cs
@@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
using Cake.Core.Configuration.Parser;
using Cake.Core.IO;
@@ -43,11 +45,27 @@ public CakeConfigurationProvider(IFileSystem fileSystem, ICakeEnvironment enviro
/// The arguments.
/// The created configuration.
public ICakeConfiguration CreateConfiguration(DirectoryPath path, IDictionary arguments)
+ => CreateConfiguration(path, Enumerable.Empty>(), arguments);
+
+ ///
+ /// Creates a configuration from the provided arguments.
+ ///
+ /// The directory to look for the configuration file.
+ /// The initial base configuration.
+ /// The arguments.
+ /// The created configuration.
+ public ICakeConfiguration CreateConfiguration(DirectoryPath path, IEnumerable> baseConfiguration, IDictionary arguments)
{
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}
+
+ if (baseConfiguration == null)
+ {
+ throw new ArgumentNullException(nameof(baseConfiguration));
+ }
+
if (arguments == null)
{
throw new ArgumentNullException(nameof(arguments));
@@ -55,6 +73,12 @@ public ICakeConfiguration CreateConfiguration(DirectoryPath path, IDictionary(StringComparer.OrdinalIgnoreCase);
+ // Add base configuration.
+ foreach (var kv in baseConfiguration)
+ {
+ result[KeyNormalizer.Normalize(kv.Key)] = kv.Value;
+ }
+
// Get all environment variables.
foreach (var variable in _environment.GetEnvironmentVariables())
{
diff --git a/src/Cake.Frosting/Extensions/ServiceCollectionExtensions.cs b/src/Cake.Frosting/Extensions/ServiceCollectionExtensions.cs
index 4b3b4392fa..e30fc7ff69 100644
--- a/src/Cake.Frosting/Extensions/ServiceCollectionExtensions.cs
+++ b/src/Cake.Frosting/Extensions/ServiceCollectionExtensions.cs
@@ -178,5 +178,16 @@ public static IServiceCollection UseCakeSetting(this IServiceCollection services
services.AddSingleton(new FrostingConfigurationValue(key, value));
return services;
}
+
+ ///
+ /// Sets the tool path configuration to the specified value.
+ ///
+ /// The service collection.
+ /// The tool path value.
+ /// The same instance so that multiple calls can be chained.
+ public static IServiceCollection UseToolPath(this IServiceCollection services, DirectoryPath toolPath)
+ {
+ return services.UseCakeSetting("paths_tools", toolPath.FullPath);
+ }
}
}
diff --git a/src/Cake.Frosting/Internal/Commands/DefaultCommand.cs b/src/Cake.Frosting/Internal/Commands/DefaultCommand.cs
index ea0d554c1d..49b4d4bae0 100644
--- a/src/Cake.Frosting/Internal/Commands/DefaultCommand.cs
+++ b/src/Cake.Frosting/Internal/Commands/DefaultCommand.cs
@@ -28,6 +28,7 @@ public override int Execute(CommandContext context, DefaultCommandSettings setti
// Register arguments
var arguments = new CakeArguments(context.Remaining.Parsed);
_services.AddSingleton(arguments);
+ _services.AddSingleton(context.Remaining);
var provider = _services.BuildServiceProvider();
diff --git a/src/Cake.Frosting/Internal/FrostingConfiguration.cs b/src/Cake.Frosting/Internal/FrostingConfiguration.cs
index e980056cb8..7e5c70001e 100644
--- a/src/Cake.Frosting/Internal/FrostingConfiguration.cs
+++ b/src/Cake.Frosting/Internal/FrostingConfiguration.cs
@@ -4,32 +4,47 @@
using System;
using System.Collections.Generic;
+using System.Linq;
+using Cake.Core;
using Cake.Core.Configuration;
+using Cake.Core.IO;
+using Spectre.Console.Cli;
namespace Cake.Frosting.Internal
{
internal sealed class FrostingConfiguration : ICakeConfiguration
{
- private readonly Dictionary _lookup;
+ private readonly ICakeConfiguration _cakeConfiguration;
- public FrostingConfiguration(IEnumerable values)
+ public FrostingConfiguration(IEnumerable values, IFileSystem fileSystem, ICakeEnvironment environment, IRemainingArguments remainingArguments)
{
if (values is null)
{
throw new ArgumentNullException(nameof(values));
}
- _lookup = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ if (fileSystem is null)
+ {
+ throw new ArgumentNullException(nameof(fileSystem));
+ }
+
+ if (environment is null)
+ {
+ throw new ArgumentNullException(nameof(environment));
+ }
+
+ var baseConfiguration = new Dictionary(StringComparer.OrdinalIgnoreCase);
foreach (var value in values)
{
- _lookup[value.Key] = value.Value;
+ baseConfiguration[value.Key] = value.Value;
}
- }
- public string GetValue(string key)
- {
- _lookup.TryGetValue(key, out var value);
- return value;
+ var provider = new CakeConfigurationProvider(fileSystem, environment);
+ var args = remainingArguments.Parsed.ToDictionary(x => x.Key, x => x.FirstOrDefault() ?? string.Empty);
+
+ _cakeConfiguration = provider.CreateConfiguration(environment.WorkingDirectory, baseConfiguration, args);
}
+
+ public string GetValue(string key) => _cakeConfiguration.GetValue(key);
}
}
diff --git a/tests/integration/Cake.Frosting/build/Build.csproj b/tests/integration/Cake.Frosting/build/Build.csproj
index 6780d1a1a5..b70d4e41a4 100644
--- a/tests/integration/Cake.Frosting/build/Build.csproj
+++ b/tests/integration/Cake.Frosting/build/Build.csproj
@@ -6,7 +6,7 @@
true
- $(MSBuildProjectDirectory)
+ $(MSBuildProjectDirectory)\..
diff --git a/tests/integration/Cake.Frosting/build/Program.cs b/tests/integration/Cake.Frosting/build/Program.cs
index 546d39bd80..3e7d183b3a 100644
--- a/tests/integration/Cake.Frosting/build/Program.cs
+++ b/tests/integration/Cake.Frosting/build/Program.cs
@@ -13,6 +13,7 @@ public void Configure(IServiceCollection services)
{
services.UseContext();
services.UseLifetime();
+ services.UseTool(new System.Uri("nuget:?package=xunit.runner.console"));
services.UseWorkingDirectory("..");
}
}
\ No newline at end of file
diff --git a/tests/integration/Cake.Frosting/cake.config b/tests/integration/Cake.Frosting/cake.config
new file mode 100644
index 0000000000..88f98ae7e2
--- /dev/null
+++ b/tests/integration/Cake.Frosting/cake.config
@@ -0,0 +1,2 @@
+[Paths]
+Tools=../tools/frostingtools
\ No newline at end of file