I'm wondering about the following code. I use powershell to load the following json file called "tool.json":
{
"1": {
"Tool": ["vhdl_component_packager"],
"Name": ["a1_stuff"],
"Dir": ["./source"],
"Recurse": ["true"],
"ExcludeVhd": ["*_tb.vhd"],
"ExcludeEntity": []
}
}
Then when I execute my script I would expect the script to read the variables in the JSON file to override the parameters of the script, namely $Dir, and set it to ./source as shown in the JSON file. But that's not happening, instead its not change $Dir... I'm wondering how to fix it.
param(
[string]$Dir = "."
)
function read_tool_json {
$tool_json = "./tool.json"
if (-not(test-path $tool_json)) {
throw "Missing ./tool.json file"
}
write-host "Reading file: $tool_json"
$tool_json = Get-Content -Raw $tool_json | ConvertFrom-Json
foreach ($item1 in $tool_json.psobject.Properties) {
write-host $item1.Name
$top_name = $item1.Name
$top_node = $tool_json.$top_name
foreach ($item2 in $top_node.psobject.Properties) {
$elem_name = $item2.Name
$elem_node = [array]$top_node.$elem_name
write-host "set-variable -name $elem_name -value $elem_node -scope global"
set-variable -name $elem_name -value $elem_node -scope global -force
$dir
}
}
}
read_tool_json
$script:Dir.GetType()
#QUESTION: how to get $script:Dir to equal "./source" from json file???
write-host "dir:($Dir)"