Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Fallout.Cli/Commands/GetConfigurationCommand.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// <c>fallout :get-configuration</c>: prints the build configuration parsed from the build script.
/// </summary>
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;
}
}
12 changes: 2 additions & 10 deletions src/Fallout.Cli/Program.GetConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> GetConfiguration(AbsolutePath buildScript, bool evaluate)
{
string ReplaceScriptDirectory(string value)
Expand Down
2 changes: 1 addition & 1 deletion src/Fallout.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private static void RegisterCommands(IServiceCollection services)
services.AddSingleton<IFalloutCommand, RunCommand>();
services.AddSingleton<IFalloutCommand, TriggerCommand>();
services.AddSingleton<IFalloutCommand, CompleteCommand>();
services.AddSingleton<IFalloutCommand, GetConfigurationCommand>();

// 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.
Expand All @@ -63,7 +64,6 @@ private static void RegisterCommands(IServiceCollection services)
services.AddSingleton<IFalloutCommand>(new DelegateCommand("add-package", AddPackage));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("cake-convert", CakeConvert));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("cake-clean", CakeClean));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("get-configuration", GetConfiguration));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("secrets", Secrets));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("GetNextDirectory", GetNextDirectory));
services.AddSingleton<IFalloutCommand>(new DelegateCommand("PopDirectory", PopDirectory));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}