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:
parent
d44c80280e
commit
00668b1544
1 changed files with 14 additions and 16 deletions
|
@ -21,12 +21,6 @@ $ErrorActionPreference = "Stop"
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
# POWERSHELL_COMMON
|
# 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
|
Function Find-Command
|
||||||
{
|
{
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
@ -103,8 +97,8 @@ Function Install-WithWebPICmd
|
||||||
|
|
||||||
if ($LastExitCode -ne 0)
|
if ($LastExitCode -ne 0)
|
||||||
{
|
{
|
||||||
Set-Attr $result "webpicmd_error_cmd" $cmd
|
$result.webpicmd_error_cmd = $cmd
|
||||||
Set-Attr $result "webpicmd_error_log" "$results"
|
$result.webpicmd_error_log = "$results"
|
||||||
Throw "Error installing $package"
|
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
|
$script:executable = Find-WebPiCmd
|
||||||
if ((Test-IsInstalledFromWebPI -package $package) -eq $false)
|
if ((Test-IsInstalledFromWebPI -package $package) -eq $false) {
|
||||||
{
|
|
||||||
Install-WithWebPICmd -package $package
|
Install-WithWebPICmd -package $package
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json $result
|
||||||
}
|
} Catch {
|
||||||
Catch
|
|
||||||
{
|
|
||||||
Fail-Json $result $_.Exception.Message
|
Fail-Json $result $_.Exception.Message
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue