strict variables fix

This commit is contained in:
Hans-Joachim Kliemeck 2015-10-21 17:52:59 +02:00
parent 461a479cbd
commit e7fd5dcde0

View file

@ -24,96 +24,22 @@ $ErrorActionPreference = "Stop"
# POWERSHELL_COMMON # POWERSHELL_COMMON
$params = Parse-Args $args; $params = Parse-Args $args;
$result = New-Object PSObject; $result = New-Object PSObject;
Set-Attr $result "changed" $false; Set-Attr $result "changed" $false;
$name = Get-Attr $params "name" -failifempty $true
$state = Get-Attr $params "state" "present" -validateSet "present", "absent", "started", "stopped", "restarted" -resultobj $result
If ($params.name) $application = Get-Attr $params "application" $null
{ $appParameters = Get-Attr $params "app_parameters" $null
$name = $params.name
}
Else
{
Fail-Json $result "missing required argument: name"
}
If ($params.state) $stdoutFile = Get-Attr $params "stdout_file" $null
{ $stderrFile = Get-Attr $params "stderr_file" $null
$state = $params.state.ToString().ToLower() $dependencies = Get-Attr $params "dependencies" $null
$validStates = "present", "absent", "started", "stopped", "restarted"
If ($validStates -notcontains $state) $user = Get-Attr $params "user" $null
{ $password = Get-Attr $params "password" $null
Fail-Json $result "state is $state; must be one of: $validStates"
}
}
else
{
$state = "present"
}
If ($params.application)
{
$application = $params.application
}
Else
{
$application = $null
}
If ($params.app_parameters)
{
$appParameters = $params.app_parameters
}
Else
{
$appParameters = $null
}
If ($params.stdout_file)
{
$stdoutFile = $params.stdout_file
}
Else
{
$stdoutFile = $null
}
If ($params.stderr_file)
{
$stderrFile = $params.stderr_file
}
Else
{
$stderrFile = $null
}
If ($params.dependencies)
{
$dependencies = $params.dependencies
}
Else
{
$dependencies = $null
}
If ($params.user)
{
$user = $params.user
}
Else
{
$user = $null
}
If ($params.password)
{
$password = $params.password
}
Else
{
$password = $null
}
Function Service-Exists Function Service-Exists
{ {