Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --outdir param with build-params #13890

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ public async Task Build_Valid_Params_File_Should_Succeed(BaselineData_Bicepparam
data.Compiled!.ShouldHaveExpectedJsonValue();
}

[DataTestMethod]
[BaselineData_Bicepparam.TestData(Filter = BaselineData_Bicepparam.TestDataFilterType.ValidOnly)]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public async Task Build_Valid_Params_File_To_Outdir_Should_Succeed(BaselineData_Bicepparam baselineData)
{
var data = baselineData.GetData(TestContext);
var (output, error, result) = await Bicep(Settings, "build-params", data.Parameters.OutputFilePath, "--bicep-file", data.Bicep.OutputFilePath, "--outdir", Path.GetDirectoryName(data.Compiled!.OutputFilePath));

using (new AssertionScope())
{
result.Should().Be(0);
output.Should().BeEmpty();
AssertNoErrors(error);
}

data.Compiled!.ShouldHaveExpectedJsonValue();
}

[DataTestMethod]
[BaselineData_Bicepparam.TestData(Filter = BaselineData_Bicepparam.TestDataFilterType.ValidOnly)]
[TestCategory(BaselineHelper.BaselineTestCategory)]
Expand Down
29 changes: 27 additions & 2 deletions src/Bicep.Cli/Arguments/BuildParamsArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ public BuildParamsArguments(string[] args) : base(Constants.Command.BuildParams)
i++;
break;

case "--outdir":
if (args.Length == i + 1)
{
throw new CommandLineException($"The --outdir parameter expects an argument");
}
if (OutputDir is not null)
{
throw new CommandLineException($"The --outdir parameter cannot be specified twice");
}
OutputDir = args[i + 1];
i++;
break;

case "--outfile":
if (args.Length == i + 1)
{
Expand Down Expand Up @@ -79,9 +92,19 @@ public BuildParamsArguments(string[] args) : base(Constants.Command.BuildParams)
throw new CommandLineException($"The parameters file path was not specified");
}

if (OutputFile is not null && OutputToStdOut)
if (OutputToStdOut && OutputDir is not null)
{
throw new CommandLineException($"The --stdout can not be used when --outfile is specified");
throw new CommandLineException($"The --outdir and --stdout parameters cannot both be used");
}

if (OutputToStdOut && OutputFile is not null)
{
throw new CommandLineException($"The --outfile and --stdout parameters cannot both be used");
}

if (OutputDir is not null && OutputFile is not null)
{
throw new CommandLineException($"The --outdir and --outfile parameters cannot both be used");
}

if (DiagnosticsFormat is null)
Expand All @@ -96,6 +119,8 @@ public BuildParamsArguments(string[] args) : base(Constants.Command.BuildParams)

public string? BicepFile { get; }

public string? OutputDir { get; }

public string? OutputFile { get; }

public DiagnosticsFormat? DiagnosticsFormat { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Cli/Commands/BuildParamsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public async Task<int> RunAsync(BuildParamsArguments args)
}
else
{
var paramsOutputPath = PathHelper.ResolveDefaultOutputPath(paramsFileUri.LocalPath, null, args.OutputFile, PathHelper.GetDefaultBuildOutputPath);
var outputPath = PathHelper.ResolveDefaultOutputPath(paramsFileUri.LocalPath, args.OutputDir, args.OutputFile, PathHelper.GetDefaultBuildOutputPath);

writer.ParametersToFile(compilation, PathHelper.FilePathToFileUrl(paramsOutputPath));
writer.ParametersToFile(compilation, PathHelper.FilePathToFileUrl(outputPath));
}
}

Expand Down
Loading