diff --git a/src/GitVersionCore/Arguments.cs b/src/GitVersionCore/Arguments.cs index 8ccaac4ee4..1c13eac3eb 100644 --- a/src/GitVersionCore/Arguments.cs +++ b/src/GitVersionCore/Arguments.cs @@ -44,7 +44,7 @@ public class Arguments public bool NoCache; public bool NoNormalize; - public OutputType Output = OutputType.Json; + public ISet Output = new HashSet(); public Verbosity Verbosity = Verbosity.Normal; public bool UpdateAssemblyInfo; diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 575577913d..c279ae11ca 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -135,28 +135,54 @@ public void UnknownOutputShouldThrow() public void OutputDefaultsToJson() { var arguments = argumentParser.ParseArguments("targetDirectoryPath"); - arguments.Output.ShouldBe(OutputType.Json); + arguments.Output.ShouldContain(OutputType.Json); } [Test] public void OutputJsonCanBeParsed() { var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json"); - arguments.Output.ShouldBe(OutputType.Json); + arguments.Output.ShouldContain(OutputType.Json); + arguments.Output.ShouldNotContain(OutputType.BuildServer); + } + + [Test] + public void MultipleOutputJsonCanBeParsed() + { + var arguments = argumentParser.ParseArguments("targetDirectoryPath -output json -output json"); + arguments.Output.ShouldContain(OutputType.Json); + arguments.Output.ShouldNotContain(OutputType.BuildServer); } [Test] public void OutputBuildserverCanBeParsed() { var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver"); - arguments.Output.ShouldBe(OutputType.BuildServer); + arguments.Output.ShouldContain(OutputType.BuildServer); + arguments.Output.ShouldNotContain(OutputType.Json); + } + + [Test] + public void MultipleOutputBuildserverCanBeParsed() + { + var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output buildserver"); + arguments.Output.ShouldContain(OutputType.BuildServer); + arguments.Output.ShouldNotContain(OutputType.Json); + } + + [Test] + public void OutputBuildserverAndJsonCanBeParsed() + { + var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -output json"); + arguments.Output.ShouldContain(OutputType.BuildServer); + arguments.Output.ShouldContain(OutputType.Json); } [Test] public void MultipleArgsAndFlag() { var arguments = argumentParser.ParseArguments("targetDirectoryPath -output buildserver -updateAssemblyInfo"); - arguments.Output.ShouldBe(OutputType.BuildServer); + arguments.Output.ShouldContain(OutputType.BuildServer); } [Test] diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index 53b1535c50..e85c536885 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -34,10 +34,13 @@ public Arguments ParseArguments(string[] commandLineArguments) { if (commandLineArguments.Length == 0) { - return new Arguments + var args = new Arguments { TargetPath = System.Environment.CurrentDirectory, }; + + args.Output.Add(OutputType.Json); + return args; } var firstArgument = commandLineArguments.First(); @@ -264,12 +267,16 @@ public Arguments ParseArguments(string[] commandLineArguments) if (name.IsSwitch("output")) { - if (!Enum.TryParse(value, true, out OutputType outputType)) + foreach (var v in values) { - throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'"); + if (!Enum.TryParse(v, true, out OutputType outputType)) + { + throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'"); + } + + arguments.Output.Add(outputType); } - arguments.Output = outputType; continue; } @@ -396,6 +403,11 @@ public Arguments ParseArguments(string[] commandLineArguments) throw new WarningException(couldNotParseMessage); } + if (arguments.Output.Count == 0) + { + arguments.Output.Add(OutputType.Json); + } + if (arguments.TargetPath == null) { // If the first argument is a switch, it should already have been consumed in the above loop, diff --git a/src/GitVersionExe/ExecCommand.cs b/src/GitVersionExe/ExecCommand.cs index 01ae930133..8098f48ff9 100644 --- a/src/GitVersionExe/ExecCommand.cs +++ b/src/GitVersionExe/ExecCommand.cs @@ -40,32 +40,28 @@ public void Execute() var arguments = options.Value; - switch (arguments.Output) + if (arguments.Output.Contains(OutputType.BuildServer)) { - case OutputType.BuildServer: - var buildServer = buildServerResolver.Resolve(); - buildServer?.WriteIntegration(Console.WriteLine, variables); - - break; - case OutputType.Json: - switch (arguments.ShowVariable) - { - case null: - Console.WriteLine(variables.ToString()); - break; - - default: - if (!variables.TryGetValue(arguments.ShowVariable, out var part)) - { - throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); - } - Console.WriteLine(part); - break; - } - - break; - default: - throw new ArgumentOutOfRangeException(); + var buildServer = buildServerResolver.Resolve(); + buildServer?.WriteIntegration(Console.WriteLine, variables); + } + if (arguments.Output.Contains(OutputType.Json)) + { + switch (arguments.ShowVariable) + { + case null: + Console.WriteLine(variables.ToString()); + break; + + default: + if (!variables.TryGetValue(arguments.ShowVariable, out var part)) + { + throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); + } + + Console.WriteLine(part); + break; + } } if (arguments.UpdateWixVersionFile) diff --git a/src/GitVersionExe/GitVersionExecutor.cs b/src/GitVersionExe/GitVersionExecutor.cs index 8d37dfafc9..36cb3503cd 100644 --- a/src/GitVersionExe/GitVersionExecutor.cs +++ b/src/GitVersionExe/GitVersionExecutor.cs @@ -73,12 +73,12 @@ private int VerifyArgumentsAndRun(Arguments arguments) if (arguments.Diag) { arguments.NoCache = true; - arguments.Output = OutputType.BuildServer; + arguments.Output.Add(OutputType.BuildServer); } if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec)) { - arguments.Output = OutputType.BuildServer; + arguments.Output.Add(OutputType.BuildServer); } var buildServer = buildServerResolver.Resolve(); @@ -154,7 +154,7 @@ private void VerifyConfiguration() private static void ConfigureLogging(Arguments arguments, ILog log) { - if (arguments.Output == OutputType.BuildServer || arguments.LogFilePath == "console" || arguments.Init) + if (arguments.Output.Contains(OutputType.BuildServer) || arguments.LogFilePath == "console" || arguments.Init) { log.AddLogAppender(new ConsoleAppender()); }