mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-12-12 02:56:03 +00:00
Add jsonpath support for checkver and hash extraction
Unravel if-blocks in checkver Use new jsonpath for openssl, nuget, dart and bfg
This commit is contained in:
27
lib/json.ps1
27
lib/json.ps1
@@ -86,3 +86,30 @@ Function ConvertToPrettyJson {
|
||||
$output
|
||||
}
|
||||
}
|
||||
|
||||
function json_path([Object] $json, [String] $jsonpath, [String] $basename) {
|
||||
$result = $json
|
||||
$isJsonPath = $jsonpath.StartsWith("`$")
|
||||
$jsonpath.split(".") | ForEach-Object {
|
||||
$el = $_
|
||||
|
||||
# substitute the base filename into the jsonpath
|
||||
if($el.StartsWith("`$basename")) {
|
||||
$el = $el.Replace("`$basename", $basename)
|
||||
}
|
||||
|
||||
# skip $ if it's jsonpath format
|
||||
if($el -eq "`$" -and $isJsonPath) {
|
||||
return
|
||||
}
|
||||
|
||||
if($el -match "^(?<property>\w+)\[(?<index>\d+)\]$") {
|
||||
$property = $matches['property']
|
||||
$result = $result.$property[$matches['index']]
|
||||
return
|
||||
}
|
||||
|
||||
$result = $result.$el
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user