Skip to content

Commit 7227f18

Browse files
committed
GH-2127 - allow only buildserver
1 parent 97b0ce4 commit 7227f18

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/GitVersionCore/Arguments.cs

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

1713
public Config OverrideConfig;

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,31 @@ public void OutputJsonCanBeParsed()
143143
{
144144
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json");
145145
arguments.Output.ShouldContain(OutputType.Json);
146+
arguments.Output.ShouldNotContain(OutputType.BuildServer);
147+
}
148+
149+
[Test]
150+
public void MultipleOutputJsonCanBeParsed()
151+
{
152+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json -output json");
153+
arguments.Output.ShouldContain(OutputType.Json);
154+
arguments.Output.ShouldNotContain(OutputType.BuildServer);
146155
}
147156

148157
[Test]
149158
public void OutputBuildserverCanBeParsed()
150159
{
151160
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver");
152161
arguments.Output.ShouldContain(OutputType.BuildServer);
162+
arguments.Output.ShouldNotContain(OutputType.Json);
163+
}
164+
165+
[Test]
166+
public void MultipleOutputBuildserverCanBeParsed()
167+
{
168+
var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output buildserver");
169+
arguments.Output.ShouldContain(OutputType.BuildServer);
170+
arguments.Output.ShouldNotContain(OutputType.Json);
153171
}
154172

155173
[Test]

src/GitVersionExe/ArgumentParser.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,16 @@ public Arguments ParseArguments(string[] commandLineArguments)
264264

265265
if (name.IsSwitch("output"))
266266
{
267-
if (!Enum.TryParse(value, true, out OutputType outputType))
267+
foreach (var v in values)
268268
{
269-
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
269+
if (!Enum.TryParse(v, true, out OutputType outputType))
270+
{
271+
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
272+
}
273+
274+
arguments.Output.Add(outputType);
270275
}
271276

272-
arguments.Output.Add(outputType);
273277
continue;
274278
}
275279

@@ -396,6 +400,11 @@ public Arguments ParseArguments(string[] commandLineArguments)
396400
throw new WarningException(couldNotParseMessage);
397401
}
398402

403+
if (arguments.Output.Count == 0)
404+
{
405+
arguments.Output.Add(OutputType.Json);
406+
}
407+
399408
if (arguments.TargetPath == null)
400409
{
401410
// If the first argument is a switch, it should already have been consumed in the above loop,

0 commit comments

Comments
 (0)