-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportYaml.ps1
31 lines (29 loc) · 955 Bytes
/
ImportYaml.ps1
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
function Import-Yaml {
<#
.Synopsis
Returns matching nodes/values of a path expression for a given yaml document
#>
param(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[AllowEmptyString()]
$Path,
$Pattern,
[ValidateSet('value', 'path', 'pathvalue')]
$PrintMode = 'value'
)
Process {
if ($Path -is [System.IO.FileSystemInfo]) {
$fullName = $Path.FullName
}
else {
$fullName = Resolve-Path $Path -ErrorAction SilentlyContinue
}
if ($fullName) {
switch ($PrintMode) {
"value" { &$script:yq r $fullName $Pattern --tojson | ConvertFrom-Json }
"path" { &$script:yq r $fullName $Pattern --printMode p }
"pathvalue" { &$script:yq r $fullName $Pattern --printMode pv }
}
}
}
}