Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.

Expand path for template conversion #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions src/Commands/ConvertFromArmTemplateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// Licensed under the MIT License.

using PSArm.Commands.Internal;
using PSArm.Internal;
using PSArm.Serialization;
using PSArm.Templates;
using System;
using System.IO;
using System.Management.Automation;

namespace PSArm.Commands
Expand All @@ -25,6 +27,7 @@ public ConvertFromArmTemplateCommand()
}

[ValidateNotNullOrEmpty]
[SupportsWildcards]
[Parameter(ParameterSetName = "Path", Position = 0, Mandatory = true)]
public string[] Path { get; set; }

Expand All @@ -49,9 +52,34 @@ protected override void ProcessRecord()
return;

case "Path":
foreach (string path in Path)
foreach (string wildcardPath in Path)
{
WriteObject(_parser.ParseFile(path));
foreach (string path in GetResolvedProviderPathFromPSPath(wildcardPath, out ProviderInfo provider))
{
if (!provider.Name.Is("FileSystem"))
{
WriteError(
new ErrorRecord(
new IOException($"Cannot convert non-filesystem template path '{path}'"),
"BadProviderPath",
ErrorCategory.InvalidArgument,
path));
continue;
}

if (!File.Exists(path))
{
WriteError(
new ErrorRecord(
new FileNotFoundException($"ARM template file '{path}' does not exist"),
"TemplateFileNotFound",
ErrorCategory.ResourceUnavailable,
path));
continue;
}

WriteObject(_parser.ParseFile(path));
}
}
return;

Expand Down
10 changes: 10 additions & 0 deletions test/pester/Conversion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ Describe "ARM conversion cmdlets" {

Assert-StructurallyEqual -ComparisonObject $original -JsonObject $created
}

It 'Can accept relative path' {
try {
Push-Location "$PSScriptRoot/assets"
ConvertFrom-ArmTemplate -Path ./roundtrip-template.json | Should -Not -BeNullOrEmpty
}
finally {
Pop-Location
}
}
}