Powershell が関数を処理する方法を理解できません。次のスクリプトでは、メイン関数を実際に呼び出していなくても、すべての関数が呼び出されます。powershell にはコール チェーンの概念がありませんか?
param([string]$directory)
[string]$global:sqlscript;
$global:types = @{
"double" = "DOUBLE PRECISION";
"int" = "INTEGER";
"QString" = "INTEGER";
"Ignored" = "1";
"Normal" = "2";
"Critical" = "3" }
function resultToSql($element)
{
$global:sqlscript += ('"')
$global:sqlscript += ($element.name + '" ')
$global:sqlscript += ($global:types.Get_Item($element.type))
$global:sqlscript += (',' + [Environment]::Newline)
$global:sqlscript += ('"' + $element.name + "_metric_group" + " " + $global:types.Get_Item($element.metric_group.type))
$global:sqlscript += (',' + [Environment]::Newline)
}
function xmlToSql($source)
{
Write-Host "Parsing...";
$global:sqlscript += "CREATE TABLE IF NOT EXISTS " + '"' + $source.spec.task.ToLower() + '"'+ [Environment]::NewLine
$global:sqlscript += '"' + "id" + '"' + " SERIAL NOT NULL" + [Environment]::NewLine
foreach ($node in $source.spec.measure) {
resultToSql $node
}
foreach ($m in $source.spec.error) {
resultToSql $m
}
$global:sqlscript += '"' + "weighted_sum" + '" ' + $global:types.Get_Item("double") + [Environment]::Newline;
}
function main
{
if ($directory -eq $null) { exit }
else
{
$xmlfiles = Get-ChildItem -Path $directory -include *Spec.xml
foreach ($xmlfile in $xmlfiles)
{
Write-Host "Filename:" $xmlfile;
[xml]$spec = Get-Content $file;
xmlToSql $spec;
Write-Host $script;
}
}
}