GH4687: Trim leading hyphens from command-line argument keys in FrostingConfiguration#4669
Conversation
devlead
left a comment
There was a problem hiding this comment.
Like Cake.Tool and Cake.Sdk utilize ICakeArguments instead of Specre.Console.Cli ICakeArguments so we'vegot consistent behaviour.
@@ -8,7 +8,6 @@ using System.Linq;
using Cake.Core;
using Cake.Core.Configuration;
using Cake.Core.IO;
-using Spectre.Console.Cli;
namespace Cake.Frosting.Internal
{
@@ -16,7 +15,7 @@ namespace Cake.Frosting.Internal
{
private readonly ICakeConfiguration _cakeConfiguration;
- public FrostingConfiguration(IEnumerable<FrostingConfigurationValue> values, IFileSystem fileSystem, ICakeEnvironment environment, IRemainingArguments remainingArguments)
+ public FrostingConfiguration(IEnumerable<FrostingConfigurationValue> values, IFileSystem fileSystem, ICakeEnvironment environment, ICakeArguments arguments)
{
ArgumentNullException.ThrowIfNull(values);
@@ -24,6 +23,8 @@ namespace Cake.Frosting.Internal
ArgumentNullException.ThrowIfNull(environment);
+ ArgumentNullException.ThrowIfNull(arguments);
+
var baseConfiguration = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var value in values)
{
@@ -31,7 +32,7 @@ namespace Cake.Frosting.Internal
}
var provider = new CakeConfigurationProvider(fileSystem, environment);
- var args = remainingArguments.Parsed.ToDictionary(x => x.Key.TrimStart('-'), x => x.FirstOrDefault() ?? string.Empty);
+ var args = arguments.GetArguments().ToDictionary(x => x.Key, x => x.Value?.FirstOrDefault() ?? string.Empty);
_cakeConfiguration = provider.CreateConfiguration(environment.WorkingDirectory, baseConfiguration, args);
}
To test this you could add som configuration validation in Frosting integration test
https://github.com/cake-build/cake/tree/develop/tests/integration/Cake.Frosting/build
It's called here
Lines 374 to 384 in 3531435
4edcc73 to
b96c8e7
Compare
devlead
left a comment
There was a problem hiding this comment.
To test this add som configuration validation in Frosting integration test project here:
https://github.com/cake-build/cake/tree/develop/tests/integration/Cake.Frosting/build
It's called here:
Lines 374 to 384 in 3531435
Any example I could follow? Wouldn't it be better if there were also unit tests? |
You can add arguments here Lines 375 to 377 in 3531435 Environment variables can be set on the DotNetRunSettings using EnvironmentVariables property. Config file is here: cake/tests/integration/Cake.Frosting/cake.config Lines 1 to 2 in 3531435 Which then should be able to be picked up in a task here
Integration test would E"E, but Unit tests won't hurt, Frosting specific tests are located here |
I couldn't figure out how to assert the results using the tasks you pointed to, but I added unit tests. |
`FrostingConfiguration.cs` file to ensure consistent key formatting when processing arguments. This change improves compatibility and standardization in the `args` dictionary.
Add Config task to validate configuration from multiple sources: - Environment variables (CAKE_INTEGRATIONTEST_ENVIRONMENT) - INI file configuration (cake.config) - Command-line arguments (--IntegrationTest_Argument) Changes: - Add Config task with xunit assertions to verify all config sources - Update build script to pass test arguments and environment variables - Add xunit.v3.assert package reference for assertions - Fix working directory from ".." to "." in Program.cs - Add [IntegrationTest] section to cake.config - Use nameof() for task names instead of string literals - Make verbosity configurable via integration-tests-verbosity argument
1138f05 to
2854290
Compare
devlead
left a comment
There was a problem hiding this comment.
I couldn't figure out how to assert the results using the tasks you pointed to, but I added unit tests.
I've added the integration tests,
LGTM now.
|
@paulomorgado your changes have been merged, thanks for your contribution 👍 |
@devlead, thank you for your help. |
Trim leading hyphens from command-line argument keys in the
FrostingConfiguration.csfile to ensure consistent keyformatting when processing arguments. This change improves
compatibility and standardization in the
argsdictionary.Addresses https://github.com/orgs/cake-build/discussions/4665