From d7cc0f60c9cd001f031c4465e5a94eeae94f2140 Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Wed, 23 Sep 2015 20:49:26 +0200 Subject: [PATCH] win_chocolatey bugfixes --- windows/win_chocolatey.ps1 | 72 ++++++-------------------------------- 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/windows/win_chocolatey.ps1 b/windows/win_chocolatey.ps1 index 4a033d23157..ce006fff152 100644 --- a/windows/win_chocolatey.ps1 +++ b/windows/win_chocolatey.ps1 @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -$ErrorActionPreference = "Stop" # WANT_JSON # POWERSHELL_COMMON @@ -25,72 +24,21 @@ $params = Parse-Args $args; $result = New-Object PSObject; Set-Attr $result "changed" $false; -If ($params.name) -{ - $package = $params.name -} -Else -{ - Fail-Json $result "missing required argument: name" -} - -If ($params.force) -{ - $force = $params.force | ConvertTo-Bool -} -Else -{ - $force = $false -} +$package = Get-Attr -obj $params -name name -failifempty $true -emptyattributefailmessage "missing required argument: name" +$force = Get-Attr -obj $params -name force -default "false" | ConvertTo-Bool +$upgrade = Get-Attr -obj $params -name upgrade -default "false" | ConvertTo-Bool +$version = Get-Attr -obj $params -name version -default $null -If ($params.upgrade) -{ - $upgrade = $params.upgrade | ConvertTo-Bool -} -Else -{ - $upgrade = $false -} +$source = Get-Attr -obj $params -name source -default $null +if ($source) {$source = $source.Tolower()} -If ($params.version) -{ - $version = $params.version -} -Else +$showlog = Get-Attr -obj $params -name showlog -default "false" | ConvertTo-Bool +$state = Get-Attr -obj $params -name state -default "present" +if ("present","absent" -notcontains $state) { - $version = $null + Fail-Json $result "state is $state; must be present or absent" } -If ($params.source) -{ - $source = $params.source.ToString().ToLower() -} -Else -{ - $source = $null -} - -If ($params.showlog) -{ - $showlog = $params.showlog | ConvertTo-Bool -} -Else -{ - $showlog = $null -} - -If ($params.state) -{ - $state = $params.state.ToString().ToLower() - If (($state -ne "present") -and ($state -ne "absent")) - { - Fail-Json $result "state is $state; must be present or absent" - } -} -Else -{ - $state = "present" -} Function Chocolatey-Install-Upgrade {