forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildCommand.cs
More file actions
71 lines (60 loc) · 2.36 KB
/
Copy pathBuildCommand.cs
File metadata and controls
71 lines (60 loc) · 2.36 KB
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
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.Cli.Arguments;
using Bicep.Cli.Logging;
using Bicep.Cli.Services;
using Bicep.Core.FileSystem;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
namespace Bicep.Cli.Commands
{
public class BuildCommand : ICommand
{
private readonly ILogger logger;
private readonly IDiagnosticLogger diagnosticLogger;
private readonly InvocationContext invocationContext;
private readonly CompilationService compilationService;
private readonly CompilationWriter writer;
public BuildCommand(
ILogger logger,
IDiagnosticLogger diagnosticLogger,
InvocationContext invocationContext,
CompilationService compilationService,
CompilationWriter writer)
{
this.logger = logger;
this.diagnosticLogger = diagnosticLogger;
this.invocationContext = invocationContext;
this.compilationService = compilationService;
this.writer = writer;
}
public async Task<int> RunAsync(BuildArguments args)
{
var inputPath = PathHelper.ResolvePath(args.InputFile);
if (invocationContext.EmitterSettings.EnableSymbolicNames)
{
logger.LogWarning(CliResources.SymbolicNamesDisclaimerMessage);
}
if (invocationContext.Features.ResourceTypedParamsAndOutputsEnabled)
{
logger.LogWarning(CliResources.ResourceTypesDisclaimerMessage);
}
var compilation = await compilationService.CompileAsync(inputPath, args.NoRestore);
if (diagnosticLogger.ErrorCount < 1)
{
if (args.OutputToStdOut)
{
writer.ToStdout(compilation);
}
else
{
static string DefaultOutputPath(string path) => PathHelper.GetDefaultBuildOutputPath(path);
var outputPath = PathHelper.ResolveDefaultOutputPath(inputPath, args.OutputDir, args.OutputFile, DefaultOutputPath);
writer.ToFile(compilation, outputPath);
}
}
// return non-zero exit code on errors
return diagnosticLogger.ErrorCount > 0 ? 1 : 0;
}
}
}