From df8866b8bd1b9672db236a1da50dee9fd3251366 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 19 Jun 2014 11:32:48 -0500 Subject: [PATCH] Add examples for how to use powershell common functions --- lib/ansible/module_utils/powershell.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1 index 37366f0d61..919bf19532 100644 --- a/lib/ansible/module_utils/powershell.ps1 +++ b/lib/ansible/module_utils/powershell.ps1 @@ -29,6 +29,7 @@ # Helper function to parse Ansible JSON arguments from a file passed as # the single argument to the module +# Example: $params = Parse-Args $args Function Parse-Args($arguments) { $parameters = New-Object psobject; @@ -42,6 +43,7 @@ Function Parse-Args($arguments) # Helper function to set an "attribute" on a psobject instance in powershell. # This is a convenience to make adding Members to the object easier and # slightly more pythonic +# Example: Set-Attr $result "changed" $true Function Set-Attr($obj, $name, $value) { $obj | Add-Member -Force -MemberType NoteProperty -Name $name -Value $value @@ -66,6 +68,7 @@ Function Get-Attr($obj, $name, $default = $null) # Helper function to convert a powershell object to JSON to echo it, exiting # the script +# Example: Exit-Json $result Function Exit-Json($obj) { echo $obj | ConvertTo-Json @@ -74,6 +77,7 @@ Function Exit-Json($obj) # Helper function to add the "msg" property and "failed" property, convert the # powershell object to JSON and echo it, exiting the script +# Example: Fail-Json $result "This is the failure message" Function Fail-Json($obj, $message) { Set-Attr $obj "msg" $message @@ -84,6 +88,7 @@ Function Fail-Json($obj, $message) # Helper filter/pipeline function to convert a value to boolean following current # Ansible practices +# Example: $is_true = "true" | ConvertTo-Bool Function ConvertTo-Bool { param(