From d1423254d0008f3ab42a681455f64edfcf2c3cd4 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Thu, 19 Jun 2014 12:14:57 -0500 Subject: [PATCH] Update slurp/win_ping/win_stat to use Get-Attr. --- windows/slurp.ps1 | 50 ++++++++++++++------------------------------ windows/win_ping.ps1 | 7 ++----- windows/win_stat.ps1 | 12 ++--------- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/windows/slurp.ps1 b/windows/slurp.ps1 index da2404d02f9..edf1da7635f 100644 --- a/windows/slurp.ps1 +++ b/windows/slurp.ps1 @@ -19,46 +19,28 @@ $params = Parse-Args $args; -$src = ''; -If ($params.src.GetType) -{ - $src = $params.src; -} -Else -{ - If ($params.path.GetType) - { - $src = $params.path; - } -} +$src = Get-Attr $params "src" (Get-Attr $params "path" $FALSE); If (-not $src) { - $result = New-Object psobject @{}; - Fail-Json $result "missing required argument: src"; + Fail-Json (New-Object psobject) "missing required argument: src"; } -If (Test-Path $src) +If (Test-Path -PathType Leaf $src) { - If ((Get-Item $src).Directory) # Only files have the .Directory attribute. - { - $bytes = [System.IO.File]::ReadAllBytes($src); - $content = [System.Convert]::ToBase64String($bytes); - - $result = New-Object psobject @{ - changed = $false - encoding = "base64" - }; - Set-Attr $result "content" $content; - Exit-Json $result; - } - Else - { - $result = New-Object psobject @{}; - Fail-Json $result ("is a directory: " + $src); - } + $bytes = [System.IO.File]::ReadAllBytes($src); + $content = [System.Convert]::ToBase64String($bytes); + $result = New-Object psobject @{ + changed = $false + encoding = "base64" + content = $content + }; + Exit-Json $result; +} +ElseIf (Test-Path -PathType Container $src) +{ + Fail-Json (New-Object psobject) ("is a directory: " + $src); } Else { - $result = New-Object psobject @{}; - Fail-Json $result ("file not found: " + $src); + Fail-Json (New-Object psobject) ("file not found: " + $src); } diff --git a/windows/win_ping.ps1 b/windows/win_ping.ps1 index ec6d530025c..98f1415e290 100644 --- a/windows/win_ping.ps1 +++ b/windows/win_ping.ps1 @@ -19,14 +19,11 @@ $params = Parse-Args $args; -$data = 'pong'; -If ($params.data.GetType) -{ - $data = $params.data; -} +$data = Get-Attr $params "data" "pong"; $result = New-Object psobject @{ changed = $false ping = $data }; + Exit-Json $result; diff --git a/windows/win_stat.ps1 b/windows/win_stat.ps1 index a5748a8bda0..f60bc577ec7 100644 --- a/windows/win_stat.ps1 +++ b/windows/win_stat.ps1 @@ -19,21 +19,13 @@ $params = Parse-Args $args; -$path = $FALSE; -If ($params.path.GetType) -{ - $path = $params.path; -} +$path = Get-Attr $params "path" $FALSE; If ($path -eq $FALSE) { Fail-Json (New-Object psobject) "missing required argument: path"; } -$get_md5 = $TRUE; -If ($params.get_md5.GetType) -{ - $get_md5 = $params.get_md5 | ConvertTo-Bool; -} +$get_md5 = Get-Attr $params "get_md5" $TRUE | ConvertTo-Bool; $result = New-Object psobject @{ stat = New-Object psobject