Skip to content

Commit 280a265

Browse files
committed
GH-2127 - allow only buildserver
1 parent 37f8829 commit 280a265

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ public Arguments ParseArguments(string[] commandLineArguments)
3434
{
3535
if (commandLineArguments.Length == 0)
3636
{
37-
return new Arguments
37+
var args = new Arguments
3838
{
3939
TargetPath = System.Environment.CurrentDirectory,
4040
};
41+
42+
args.Output.Add(OutputType.Json);
43+
return args;
4144
}
4245

4346
var firstArgument = commandLineArguments.First();
@@ -264,12 +267,16 @@ public Arguments ParseArguments(string[] commandLineArguments)
264267

265268
if (name.IsSwitch("output"))
266269
{
267-
if (!Enum.TryParse(value, true, out OutputType outputType))
270+
foreach (var v in values)
268271
{
269-
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
272+
if (!Enum.TryParse(v, true, out OutputType outputType))
273+
{
274+
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
275+
}
276+
277+
arguments.Output.Add(outputType);
270278
}
271279

272-
arguments.Output.Add(outputType);
273280
continue;
274281
}
275282

@@ -396,6 +403,11 @@ public Arguments ParseArguments(string[] commandLineArguments)
396403
throw new WarningException(couldNotParseMessage);
397404
}
398405

406+
if (arguments.Output.Count == 0)
407+
{
408+
arguments.Output.Add(OutputType.Json);
409+
}
410+
399411
if (arguments.TargetPath == null)
400412
{
401413
// If the first argument is a switch, it should already have been consumed in the above loop,

src/GitVersionExe/ExecCommand.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public void Execute()
6363
break;
6464
}
6565
}
66-
else
67-
{
68-
throw new ArgumentOutOfRangeException();
69-
}
7066

7167
if (arguments.UpdateWixVersionFile)
7268
{

0 commit comments

Comments
 (0)