Skip to content

GH4687: Trim leading hyphens from command-line argument keys in FrostingConfiguration#4669

Merged
devlead merged 3 commits intocake-build:developfrom
paulomorgado:discussions/4665
Dec 11, 2025
Merged

GH4687: Trim leading hyphens from command-line argument keys in FrostingConfiguration#4669
devlead merged 3 commits intocake-build:developfrom
paulomorgado:discussions/4665

Conversation

@paulomorgado
Copy link
Copy Markdown
Contributor

Trim leading hyphens from command-line argument keys in the
FrostingConfiguration.cs file to ensure consistent key
formatting when processing arguments. This change improves
compatibility and standardization in the args dictionary.

Addresses https://github.com/orgs/cake-build/discussions/4665

Copy link
Copy Markdown
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

cake/build.cake

Lines 374 to 384 in 3531435

DotNetRun(test.Project.FullPath,
new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet")
.AppendSwitchQuoted("--name", "=", "world"),
new DotNetRunSettings
{
Configuration = parameters.Configuration,
Framework = test.Framework,
NoRestore = true,
NoBuild = true
});

@paulomorgado paulomorgado force-pushed the discussions/4665 branch 2 times, most recently from 4edcc73 to b96c8e7 Compare December 5, 2025 23:49
Copy link
Copy Markdown
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

cake/build.cake

Lines 374 to 384 in 3531435

DotNetRun(test.Project.FullPath,
new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet")
.AppendSwitchQuoted("--name", "=", "world"),
new DotNetRunSettings
{
Configuration = parameters.Configuration,
Framework = test.Framework,
NoRestore = true,
NoBuild = true
});

@paulomorgado
Copy link
Copy Markdown
Contributor Author

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:

cake/build.cake

Lines 374 to 384 in 3531435

DotNetRun(test.Project.FullPath,
new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet")
.AppendSwitchQuoted("--name", "=", "world"),
new DotNetRunSettings
{
Configuration = parameters.Configuration,
Framework = test.Framework,
NoRestore = true,
NoBuild = true
});

Any example I could follow?

Wouldn't it be better if there were also unit tests?

@devlead
Copy link
Copy Markdown
Member

devlead commented Dec 10, 2025

Any example I could follow?

You can add arguments here

cake/build.cake

Lines 375 to 377 in 3531435

new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet")
.AppendSwitchQuoted("--name", "=", "world"),

Environment variables can be set on the DotNetRunSettings using EnvironmentVariables property.

Config file is here:

[Paths]
Tools=../tools/frostingtools

Which then should be able to be picked up in a task here
https://github.com/cake-build/cake/tree/3531435a932dd112984f04798af694efa5326997/tests/integration/Cake.Frosting/build/Tasks

Wouldn't it be better if there were also unit tests?

Integration test would E"E, but Unit tests won't hurt, Frosting specific tests are located here
https://github.com/cake-build/cake/blob/3531435a932dd112984f04798af694efa5326997/src/Cake.Frosting.Tests/CakeHostTests.cs

@paulomorgado
Copy link
Copy Markdown
Contributor Author

Any example I could follow?

You can add arguments here

cake/build.cake

Lines 375 to 377 in 3531435

new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet")
.AppendSwitchQuoted("--name", "=", "world"),

Environment variables can be set on the DotNetRunSettings using EnvironmentVariables property.

Config file is here:

[Paths]
Tools=../tools/frostingtools

Which then should be able to be picked up in a task here https://github.com/cake-build/cake/tree/3531435a932dd112984f04798af694efa5326997/tests/integration/Cake.Frosting/build/Tasks

Wouldn't it be better if there were also unit tests?

Integration test would E"E, but Unit tests won't hurt, Frosting specific tests are located here https://github.com/cake-build/cake/blob/3531435a932dd112984f04798af694efa5326997/src/Cake.Frosting.Tests/CakeHostTests.cs

@devlead,

I couldn't figure out how to assert the results using the tasks you pointed to, but I added unit tests.

paulomorgado and others added 2 commits December 11, 2025 17:16
`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
@devlead devlead changed the title Trim leading hyphens from command-line argument keys in FrostingConfiguration GH4687: Trim leading hyphens from command-line argument keys in FrostingConfiguration Dec 11, 2025
@devlead devlead enabled auto-merge December 11, 2025 20:28
Copy link
Copy Markdown
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@devlead devlead disabled auto-merge December 11, 2025 20:29
@devlead devlead merged commit 68f96b3 into cake-build:develop Dec 11, 2025
16 of 17 checks passed
@devlead
Copy link
Copy Markdown
Member

devlead commented Dec 11, 2025

@paulomorgado your changes have been merged, thanks for your contribution 👍

@paulomorgado
Copy link
Copy Markdown
Contributor Author

@paulomorgado your changes have been merged, thanks for your contribution 👍

@devlead, thank you for your help.

@paulomorgado paulomorgado deleted the discussions/4665 branch March 23, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cake Frosting FrostingConfiguration Command Line parameters are not parsed correctly.

2 participants