Skip to content

Commit 789b12d

Browse files
committed
(#513) Re-use existing Config from container
When calling the showconfig command, it was re-hydrating the configuration file from disk, rather than using the existing configuration from the IoC container. This commit changes the associated methods to re-use the existing Config object, rather than creating it again from scratch. This has the result of only showing the Warning about a missing Yaml file once, and not twice.
1 parent 500c81e commit 789b12d

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/GitReleaseManager.Core.Tests/Commands/ShowConfigCommandTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System;
12
using System.Threading.Tasks;
23
using GitReleaseManager.Core.Commands;
4+
using GitReleaseManager.Core.Configuration;
35
using GitReleaseManager.Core.Helpers;
46
using GitReleaseManager.Core.Options;
57
using NSubstitute;
@@ -21,7 +23,10 @@ public void Setup()
2123
{
2224
_fileSystem = Substitute.For<IFileSystem>();
2325
_logger = Substitute.For<ILogger>();
24-
_command = new ShowConfigCommand(_fileSystem, _logger);
26+
27+
var currentDirectory = Environment.CurrentDirectory;
28+
var configuration = ConfigurationProvider.Provide(currentDirectory, _fileSystem);
29+
_command = new ShowConfigCommand(_logger, configuration);
2530
}
2631

2732
[Test]

src/GitReleaseManager.Core/Commands/ShowConfigCommand.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
using System;
21
using System.Threading.Tasks;
32
using GitReleaseManager.Core.Configuration;
4-
using GitReleaseManager.Core.Helpers;
53
using GitReleaseManager.Core.Options;
64
using Serilog;
75

86
namespace GitReleaseManager.Core.Commands
97
{
108
public class ShowConfigCommand : ICommand<ShowConfigSubOptions>
119
{
12-
private readonly IFileSystem _fileSystem;
1310
private readonly ILogger _logger;
11+
private readonly Config _config;
1412

15-
public ShowConfigCommand(IFileSystem fileSystem, ILogger logger)
13+
public ShowConfigCommand(ILogger logger, Config config)
1614
{
17-
_fileSystem = fileSystem;
1815
_logger = logger;
16+
_config = config;
1917
}
2018

2119
public Task<int> ExecuteAsync(ShowConfigSubOptions options)
2220
{
23-
var configuration = ConfigurationProvider.GetEffectiveConfigAsString(options.TargetDirectory ?? Environment.CurrentDirectory, _fileSystem);
21+
var configuration = ConfigurationProvider.GetEffectiveConfigAsString(_config);
2422
_logger.Information("{Configuration}", configuration);
2523

2624
return Task.FromResult(0);

src/GitReleaseManager.Core/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public static Config Provide(string gitDirectory, IFileSystem fileSystem)
4141
return new Config();
4242
}
4343

44-
public static string GetEffectiveConfigAsString(string currentDirectory, IFileSystem fileSystem)
44+
public static string GetEffectiveConfigAsString(Config config)
4545
{
46-
var config = Provide(currentDirectory, fileSystem);
4746
var stringBuilder = new StringBuilder();
4847
using (var stream = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
4948
{

0 commit comments

Comments
 (0)