Skip to content

Commit cab0c76

Browse files
committed
removed ConfigFileLocator from Arguments class
1 parent 2788e4d commit cab0c76

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

src/GitVersionCore/Arguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public Arguments()
2020

2121
public Config OverrideConfig;
2222
public bool HasOverrideConfig { get; set; }
23-
public IConfigFileLocator ConfigFileLocator { get; set; }
2423

2524
public string TargetPath;
25+
public string ConfigFile;
2626

2727
public string TargetUrl;
2828
public string TargetBranch;

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using GitVersion.Exceptions;
77
using GitVersion.Logging;
88
using GitVersion.OutputFormatters;
9-
using GitVersionExe.Tests.Helpers;
109

1110
namespace GitVersionExe.Tests
1211
{
@@ -18,7 +17,7 @@ public class ArgumentParserTests
1817
[SetUp]
1918
public void SetUp()
2019
{
21-
argumentParser = new ArgumentParser(new TestFileSystem(), new NullLog());
20+
argumentParser = new ArgumentParser();
2221
}
2322

2423
[Test]

src/GitVersionExe.Tests/HelpWriterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void AllArgsAreInHelp()
2828
{ "DynamicRepositoryLocation" , "/dynamicRepoLocation" },
2929
{ "IsHelp", "/?" },
3030
{ "IsVersion", "/version" },
31-
{ "UpdateWixVersionFile", "/updatewixversionfile" }
31+
{ "UpdateWixVersionFile", "/updatewixversionfile" },
32+
{ "ConfigFile", "/config" },
3233
};
3334
string helpText = null;
3435

src/GitVersionExe/ArgumentParser.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Collections.Specialized;
44
using System.IO;
55
using System.Linq;
6-
using GitVersion.Common;
7-
using GitVersion.Configuration;
86
using GitVersion.Exceptions;
97
using GitVersion.Logging;
108
using GitVersion.OutputVariables;
@@ -15,15 +13,6 @@ namespace GitVersion
1513
{
1614
public class ArgumentParser : IArgumentParser
1715
{
18-
private readonly IFileSystem fileSystem;
19-
private readonly ILog log;
20-
21-
public ArgumentParser(IFileSystem fileSystem, ILog log)
22-
{
23-
this.fileSystem = fileSystem;
24-
this.log = log;
25-
}
26-
2716
public Arguments ParseArguments()
2817
{
2918
var argumentsWithoutExeName = GetArgumentsWithoutExeName();
@@ -38,7 +27,7 @@ public Arguments ParseArguments()
3827
Console.WriteLine("Failed to parse arguments: {0}", string.Join(" ", argumentsWithoutExeName));
3928
if (!string.IsNullOrWhiteSpace(exception.Message))
4029
{
41-
log.Error(exception.Message);
30+
Console.WriteLine(exception.Message);
4231
}
4332

4433
return arguments;
@@ -58,13 +47,11 @@ public Arguments ParseArguments(string commandLineArguments)
5847

5948
public Arguments ParseArguments(List<string> commandLineArguments)
6049
{
61-
var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
6250
if (commandLineArguments.Count == 0)
6351
{
6452
return new Arguments
6553
{
6654
TargetPath = Environment.CurrentDirectory,
67-
ConfigFileLocator = configFileLocator
6855
};
6956
}
7057

@@ -75,7 +62,6 @@ public Arguments ParseArguments(List<string> commandLineArguments)
7562
return new Arguments
7663
{
7764
IsHelp = true,
78-
ConfigFileLocator = configFileLocator
7965
};
8066
}
8167

@@ -85,14 +71,10 @@ public Arguments ParseArguments(List<string> commandLineArguments)
8571
{
8672
TargetPath = Environment.CurrentDirectory,
8773
Init = true,
88-
ConfigFileLocator = configFileLocator
8974
};
9075
}
9176

92-
var arguments = new Arguments
93-
{
94-
ConfigFileLocator = configFileLocator
95-
};
77+
var arguments = new Arguments();
9678
var switchesAndValues = CollectSwitchesAndValuesFromArguments(commandLineArguments, out var firstArgumentIsSwitch);
9779

9880
for (var i = 0; i < switchesAndValues.AllKeys.Length; i++)
@@ -118,7 +100,7 @@ public Arguments ParseArguments(List<string> commandLineArguments)
118100
if (name.IsSwitch("config"))
119101
{
120102
EnsureArgumentValueCount(values);
121-
arguments.ConfigFileLocator = new NamedConfigFileLocator(value, fileSystem, log);
103+
arguments.ConfigFile = value;
122104
continue;
123105
}
124106

src/GitVersionExe/ExecCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GitVersion.Extensions;
1111
using GitVersion.Extensions.VersionAssemblyInfoResources;
1212
using GitVersion.Common;
13+
using GitVersion.Configuration;
1314
using GitVersion.Logging;
1415

1516
namespace GitVersion
@@ -19,7 +20,7 @@ public class ExecCommand
1920
private static readonly bool runningOnUnix = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
2021
public static readonly string BuildTool = GetMsBuildToolPath();
2122

22-
public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment environment, ILog log)
23+
public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator)
2324
{
2425
log.Info($"Running on {(runningOnUnix ? "Unix" : "Windows")}.");
2526

@@ -34,7 +35,7 @@ public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment en
3435
var noCache = arguments.NoCache;
3536
var noNormalize = arguments.NoNormalize;
3637

37-
var executeCore = new ExecuteCore(fileSystem, environment, log, arguments.ConfigFileLocator);
38+
var executeCore = new ExecuteCore(fileSystem, environment, log, configFileLocator);
3839
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, noNormalize);
3940

4041
switch (arguments.Output)

src/GitVersionExe/GitVersionApplication.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public class GitVersionApplication : IGitVersionApplication
1515
private readonly IFileSystem fileSystem;
1616
private readonly IEnvironment environment;
1717
private readonly ILog log;
18+
private readonly IConfigFileLocator configFileLocator;
1819
private readonly IHelpWriter helpWriter;
1920
private readonly IVersionWriter versionWriter;
2021

21-
public GitVersionApplication(IFileSystem fileSystem, IEnvironment environment, ILog log)
22+
public GitVersionApplication(IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator)
2223
{
2324
this.fileSystem = fileSystem;
2425
this.environment = environment;
2526
this.log = log;
27+
this.configFileLocator = configFileLocator;
2628

2729
versionWriter = new VersionWriter();
2830
helpWriter = new HelpWriter(versionWriter);
@@ -91,24 +93,24 @@ private int VerifyArgumentsAndRun(Arguments arguments)
9193
log.Info("Working directory: " + arguments.TargetPath);
9294
}
9395

94-
VerifyConfiguration(arguments, log);
96+
VerifyConfiguration(arguments);
9597

9698
if (arguments.Init)
9799
{
98-
ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter(), log, arguments.ConfigFileLocator);
100+
ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter(), log, configFileLocator);
99101
return 0;
100102
}
101103
if (arguments.ShowConfig)
102104
{
103-
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(arguments.TargetPath, arguments.ConfigFileLocator));
105+
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(arguments.TargetPath, configFileLocator));
104106
return 0;
105107
}
106108

107109

108110

109111
var execCommand = new ExecCommand();
110112

111-
execCommand.Execute(arguments, fileSystem, environment, log);
113+
execCommand.Execute(arguments, fileSystem, environment, log, configFileLocator);
112114
}
113115
catch (WarningException exception)
114116
{
@@ -141,10 +143,10 @@ private int VerifyArgumentsAndRun(Arguments arguments)
141143
return 0;
142144
}
143145

144-
private static void VerifyConfiguration(Arguments arguments, ILog log)
146+
private void VerifyConfiguration(Arguments arguments)
145147
{
146148
var gitPreparer = new GitPreparer(log, arguments);
147-
arguments.ConfigFileLocator.Verify(gitPreparer);
149+
configFileLocator.Verify(gitPreparer);
148150
}
149151

150152
private static void ConfigureLogging(Arguments arguments, ILog log)

src/GitVersionExe/Program.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using GitVersion.Common;
4+
using GitVersion.Configuration;
45
using GitVersion.Logging;
56
using Environment = GitVersion.Common.Environment;
67

@@ -10,16 +11,31 @@ class Program
1011
{
1112
static void Main()
1213
{
13-
var log = new Log();
1414
var fileSystem = new FileSystem();
1515
var environment = new Environment();
16-
var argumentParser = new ArgumentParser(fileSystem, log);
16+
var argumentParser = new ArgumentParser();
1717
var arguments = argumentParser.ParseArguments();
18-
log.Verbosity = arguments?.Verbosity ?? Verbosity.Normal;
1918

20-
var app = new GitVersionApplication(fileSystem, environment, log);
19+
int exitCode;
20+
if (arguments != null)
21+
{
22+
var log = new Log
23+
{
24+
Verbosity = arguments.Verbosity
25+
};
26+
27+
var configFileLocator = string.IsNullOrWhiteSpace(arguments.ConfigFile)
28+
? (IConfigFileLocator) new DefaultConfigFileLocator(fileSystem, log)
29+
: new NamedConfigFileLocator(arguments.ConfigFile, fileSystem, log);
30+
31+
var app = new GitVersionApplication(fileSystem, environment, log, configFileLocator);
2132

22-
var exitCode = app.Run(arguments);
33+
exitCode = app.Run(arguments);
34+
}
35+
else
36+
{
37+
exitCode = 1;
38+
}
2339

2440
if (Debugger.IsAttached)
2541
{

0 commit comments

Comments
 (0)