-
Notifications
You must be signed in to change notification settings - Fork 652
/
OutputGenerator.cs
65 lines (58 loc) · 2.44 KB
/
OutputGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using GitVersion.Logging;
using GitVersion.Model;
using GitVersion.OutputVariables;
using Microsoft.Extensions.Options;
namespace GitVersion.VersionConverters.OutputGenerator
{
public interface IOutputGenerator : IVersionConverter<OutputContext>
{
}
public class OutputGenerator : IOutputGenerator
{
private readonly IConsole console;
private readonly IFileSystem fileSystem;
private readonly IOptions<GitVersionOptions> options;
private readonly Lazy<GitVersionContext> versionContext;
private readonly ICurrentBuildAgent buildAgent;
public OutputGenerator(ICurrentBuildAgent buildAgent, IConsole console, IFileSystem fileSystem, IOptions<GitVersionOptions> options, Lazy<GitVersionContext> versionContext)
{
this.console = console ?? throw new ArgumentNullException(nameof(console));
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.options = options ?? throw new ArgumentNullException(nameof(options));
this.versionContext = versionContext;
this.buildAgent = buildAgent;
}
public void Execute(VersionVariables variables, OutputContext context)
{
var gitVersionOptions = options.Value;
if (gitVersionOptions.Output.Contains(OutputType.BuildServer))
{
buildAgent?.WriteIntegration(console.WriteLine, variables, versionContext.Value.Configuration.UpdateBuildNumber);
}
if (gitVersionOptions.Output.Contains(OutputType.File))
{
fileSystem.WriteAllText(context.OutputFile, variables.ToString());
}
if (gitVersionOptions.Output.Contains(OutputType.Json))
{
switch (gitVersionOptions.ShowVariable)
{
case null:
console.WriteLine(variables.ToString());
break;
default:
if (!variables.TryGetValue(gitVersionOptions.ShowVariable, out var part))
{
throw new WarningException($"'{gitVersionOptions.ShowVariable}' variable does not exist");
}
console.WriteLine(part);
break;
}
}
}
public void Dispose()
{
}
}
}