win_webpicmd: Clean up parameter handling (#21376)

Changes include:
- Use of Get-AnsibleParam and parameter types
- Replace $result PSObject with normal hash
This commit is contained in:
Dag Wieers 2017-02-20 18:28:25 +01:00 committed by jhawkesworth
parent d44c80280e
commit 00668b1544

View file

@ -21,12 +21,6 @@ $ErrorActionPreference = "Stop"
# WANT_JSON
# POWERSHELL_COMMON
$params = Parse-Args $args;
$result = New-Object PSObject;
Set-Attr $result "changed" $false;
$package = Get-AnsibleParam $params -name "name" -failifempty $true
Function Find-Command
{
[CmdletBinding()]
@ -103,8 +97,8 @@ Function Install-WithWebPICmd
if ($LastExitCode -ne 0)
{
Set-Attr $result "webpicmd_error_cmd" $cmd
Set-Attr $result "webpicmd_error_log" "$results"
$result.webpicmd_error_cmd = $cmd
$result.webpicmd_error_log = "$results"
Throw "Error installing $package"
}
@ -116,17 +110,21 @@ Function Install-WithWebPICmd
}
}
Try
{
$result = @{
changed = $false
}
$params = Parse-Args $args
$package = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
Try {
$script:executable = Find-WebPiCmd
if ((Test-IsInstalledFromWebPI -package $package) -eq $false)
{
if ((Test-IsInstalledFromWebPI -package $package) -eq $false) {
Install-WithWebPICmd -package $package
}
Exit-Json $result;
}
Catch
{
Exit-Json $result
} Catch {
Fail-Json $result $_.Exception.Message
}