Skip to content

Commit 37f8829

Browse files
committed
GH-2127 - allow json and buildserver output at the same time
1 parent 2c30bb2 commit 37f8829

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

src/GitVersionCore/Arguments.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace GitVersion
88
{
99
public class Arguments
1010
{
11+
public Arguments()
12+
{
13+
Output.Add(OutputType.Json);
14+
}
1115
public AuthenticationInfo Authentication;
1216

1317
public Config OverrideConfig;
@@ -44,7 +48,7 @@ public class Arguments
4448
public bool NoCache;
4549
public bool NoNormalize;
4650

47-
public OutputType Output = OutputType.Json;
51+
public ISet<OutputType> Output = new HashSet<OutputType>();
4852
public Verbosity Verbosity = Verbosity.Normal;
4953

5054
public bool UpdateAssemblyInfo;

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,36 @@ public void UnknownOutputShouldThrow()
135135
public void OutputDefaultsToJson()
136136
{
137137
var arguments = argumentParser.ParseArguments("targetDirectoryPath");
138-
arguments.Output.ShouldBe(OutputType.Json);
138+
arguments.Output.ShouldContain(OutputType.Json);
139139
}
140140

141141
[Test]
142142
public void OutputJsonCanBeParsed()
143143
{
144144
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json");
145-
arguments.Output.ShouldBe(OutputType.Json);
145+
arguments.Output.ShouldContain(OutputType.Json);
146146
}
147147

148148
[Test]
149149
public void OutputBuildserverCanBeParsed()
150150
{
151151
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver");
152-
arguments.Output.ShouldBe(OutputType.BuildServer);
152+
arguments.Output.ShouldContain(OutputType.BuildServer);
153+
}
154+
155+
[Test]
156+
public void OutputBuildserverAndJsonCanBeParsed()
157+
{
158+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output json");
159+
arguments.Output.ShouldContain(OutputType.BuildServer);
160+
arguments.Output.ShouldContain(OutputType.Json);
153161
}
154162

155163
[Test]
156164
public void MultipleArgsAndFlag()
157165
{
158166
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -updateAssemblyInfo");
159-
arguments.Output.ShouldBe(OutputType.BuildServer);
167+
arguments.Output.ShouldContain(OutputType.BuildServer);
160168
}
161169

162170
[Test]

src/GitVersionExe/ArgumentParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
269269
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
270270
}
271271

272-
arguments.Output = outputType;
272+
arguments.Output.Add(outputType);
273273
continue;
274274
}
275275

src/GitVersionExe/ExecCommand.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,32 @@ public void Execute()
4040

4141
var arguments = options.Value;
4242

43-
switch (arguments.Output)
43+
if (arguments.Output.Contains(OutputType.BuildServer))
4444
{
45-
case OutputType.BuildServer:
46-
var buildServer = buildServerResolver.Resolve();
47-
buildServer?.WriteIntegration(Console.WriteLine, variables);
48-
49-
break;
50-
case OutputType.Json:
51-
switch (arguments.ShowVariable)
52-
{
53-
case null:
54-
Console.WriteLine(variables.ToString());
55-
break;
56-
57-
default:
58-
if (!variables.TryGetValue(arguments.ShowVariable, out var part))
59-
{
60-
throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
61-
}
62-
Console.WriteLine(part);
63-
break;
64-
}
65-
66-
break;
67-
default:
68-
throw new ArgumentOutOfRangeException();
45+
var buildServer = buildServerResolver.Resolve();
46+
buildServer?.WriteIntegration(Console.WriteLine, variables);
47+
}
48+
if (arguments.Output.Contains(OutputType.Json))
49+
{
50+
switch (arguments.ShowVariable)
51+
{
52+
case null:
53+
Console.WriteLine(variables.ToString());
54+
break;
55+
56+
default:
57+
if (!variables.TryGetValue(arguments.ShowVariable, out var part))
58+
{
59+
throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
60+
}
61+
62+
Console.WriteLine(part);
63+
break;
64+
}
65+
}
66+
else
67+
{
68+
throw new ArgumentOutOfRangeException();
6969
}
7070

7171
if (arguments.UpdateWixVersionFile)

src/GitVersionExe/GitVersionExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ private int VerifyArgumentsAndRun(Arguments arguments)
7373
if (arguments.Diag)
7474
{
7575
arguments.NoCache = true;
76-
arguments.Output = OutputType.BuildServer;
76+
arguments.Output.Add(OutputType.BuildServer);
7777
}
7878

7979
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
8080
{
81-
arguments.Output = OutputType.BuildServer;
81+
arguments.Output.Add(OutputType.BuildServer);
8282
}
8383

8484
var buildServer = buildServerResolver.Resolve();
@@ -154,7 +154,7 @@ private void VerifyConfiguration()
154154

155155
private static void ConfigureLogging(Arguments arguments, ILog log)
156156
{
157-
if (arguments.Output == OutputType.BuildServer || arguments.LogFilePath == "console" || arguments.Init)
157+
if (arguments.Output.Contains(OutputType.BuildServer) || arguments.LogFilePath == "console" || arguments.Init)
158158
{
159159
log.AddLogAppender(new ConsoleAppender());
160160
}

0 commit comments

Comments
 (0)