From e2e0f668450084cb1adf5e85f680478d5db16a25 Mon Sep 17 00:00:00 2001 From: Chrison Simtian Date: Wed, 17 Jun 2026 22:18:40 +1200 Subject: [PATCH 1/2] Convert :get-configuration to GetConfigurationCommand Lift the :get-configuration handler into a standalone IFalloutCommand type. The shared GetConfiguration(buildScript, evaluate) helper (also used by add-package, update and cake) stays on Program as internal residual until the #392 collapse PR extracts it into a configuration service. Replaces the DelegateCommand adapter. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Commands/GetConfigurationCommand.cs | 27 +++++++++++++++++++ src/Fallout.Cli/Program.GetConfiguration.cs | 12 ++------- src/Fallout.Cli/Program.cs | 2 +- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/Fallout.Cli/Commands/GetConfigurationCommand.cs diff --git a/src/Fallout.Cli/Commands/GetConfigurationCommand.cs b/src/Fallout.Cli/Commands/GetConfigurationCommand.cs new file mode 100644 index 00000000..4af696eb --- /dev/null +++ b/src/Fallout.Cli/Commands/GetConfigurationCommand.cs @@ -0,0 +1,27 @@ +using System; +using Fallout.Common; +using Fallout.Common.IO; +using Fallout.Common.Utilities; +using Fallout.Common.Utilities.Collections; + +namespace Fallout.Cli.Commands; + +/// +/// fallout :get-configuration: prints the build configuration parsed from the build script. +/// +public sealed class GetConfigurationCommand : IFalloutCommand +{ + public string Name => "get-configuration"; + + public int Execute(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript) + { + // Program.GetConfiguration(buildScript, evaluate) is shared with add-package/update/cake; + // it moves into a configuration service in the final #392 collapse PR. + var configuration = Program.GetConfiguration(buildScript.NotNull(), evaluate: false); + + Host.Information($"Configuration from {buildScript}:"); + configuration.ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); + + return 0; + } +} diff --git a/src/Fallout.Cli/Program.GetConfiguration.cs b/src/Fallout.Cli/Program.GetConfiguration.cs index 9a9875d9..6cda748b 100644 --- a/src/Fallout.Cli/Program.GetConfiguration.cs +++ b/src/Fallout.Cli/Program.GetConfiguration.cs @@ -19,16 +19,8 @@ partial class Program private const string DOTNET_INSTALL_URL = nameof(DOTNET_INSTALL_URL); private const string DOTNET_CHANNEL = nameof(DOTNET_CHANNEL); - public static int GetConfiguration(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript) - { - var configuration = GetConfiguration(buildScript.NotNull(), evaluate: false); - - Host.Information($"Configuration from {buildScript}:"); - configuration.ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); - - return 0; - } - + // Residual after the :get-configuration command moved to GetConfigurationCommand: this helper is + // shared with add-package/update/cake and moves into a configuration service in the #392 collapse PR. internal static Dictionary GetConfiguration(AbsolutePath buildScript, bool evaluate) { string ReplaceScriptDirectory(string value) diff --git a/src/Fallout.Cli/Program.cs b/src/Fallout.Cli/Program.cs index b713e615..43ac5823 100644 --- a/src/Fallout.Cli/Program.cs +++ b/src/Fallout.Cli/Program.cs @@ -55,6 +55,7 @@ private static void RegisterCommands(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); // Legacy handlers still living on Program, adapted until they are extracted into command // types. Each conversion deletes one line here plus its Program.X.cs partial. @@ -63,7 +64,6 @@ private static void RegisterCommands(IServiceCollection services) services.AddSingleton(new DelegateCommand("add-package", AddPackage)); services.AddSingleton(new DelegateCommand("cake-convert", CakeConvert)); services.AddSingleton(new DelegateCommand("cake-clean", CakeClean)); - services.AddSingleton(new DelegateCommand("get-configuration", GetConfiguration)); services.AddSingleton(new DelegateCommand("secrets", Secrets)); services.AddSingleton(new DelegateCommand("GetNextDirectory", GetNextDirectory)); services.AddSingleton(new DelegateCommand("PopDirectory", PopDirectory)); From 1c98a9a67029004a5c5674460ec7eab1620c3811 Mon Sep 17 00:00:00 2001 From: Chrison Simtian Date: Wed, 17 Jun 2026 22:32:07 +1200 Subject: [PATCH 2/2] Add tests for GetConfigurationCommand Name resolution and parsing a build script CONFIGURATION block. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Commands/GetConfigurationCommandTests.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/Fallout.Cli.Tests/Commands/GetConfigurationCommandTests.cs diff --git a/tests/Fallout.Cli.Tests/Commands/GetConfigurationCommandTests.cs b/tests/Fallout.Cli.Tests/Commands/GetConfigurationCommandTests.cs new file mode 100644 index 00000000..23adf0ba --- /dev/null +++ b/tests/Fallout.Cli.Tests/Commands/GetConfigurationCommandTests.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using Fallout.Cli.Commands; +using Fallout.Common.IO; +using FluentAssertions; +using Xunit; + +namespace Fallout.Cli.Tests.Commands; + +public class GetConfigurationCommandTests +{ + [Fact] + public void Name_IsGetConfiguration() + => new GetConfigurationCommand().Name.Should().Be("get-configuration"); + + [Fact] + public void Execute_ParsesConfigurationBlock_ReturnsZero() + { + var dir = (AbsolutePath)Path.Combine(Path.GetTempPath(), "fallout-getcfg-" + Guid.NewGuid().ToString("N")); + dir.CreateDirectory(); + var buildScript = dir / "build.sh"; + try + { + File.WriteAllText(buildScript, string.Join("\n", + "# CONFIGURATION", + "##############", + "", + "BUILD_PROJECT_FILE=\"build/_build.csproj\"", + "TEMP_DIRECTORY=\"$SCRIPT_DIR/.fallout/temp\"", + "", + "# EXECUTION", + "dotnet run")); + + new GetConfigurationCommand().Execute([], dir, buildScript).Should().Be(0); + } + finally + { + Directory.Delete(dir, recursive: true); + } + } +}