summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-06-16 17:56:03 -0700
committerPete Higgins <pete@peterhiggins.org>2020-08-07 14:45:51 -0700
commit289d3d5a744011ef5d2c97316facc266bfb47e6c (patch)
tree3a0e8d2f674ea0603da5ad6075313f657e189c6b /lib
parent7681e6ee29695bfdece8f920b3b2d17723dedb2c (diff)
downloadchef-289d3d5a744011ef5d2c97316facc266bfb47e6c.tar.gz
Convert set_or_return use to property, copy docs from docs site.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/resource/powershell_script.rb33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index a334f945e3..20c968b842 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -39,6 +39,30 @@ class Chef
end
}
+ property :convert_boolean_return, [true, false],
+ default: false,
+ description: <<~DESC
+ Return `0` if the last line of a command is evaluated to be true or to return `1` if the last line is evaluated to be false.
+
+ When the `guard_interpreter` common attribute is set to `:powershell_script`, a string command will be evaluated as if this value were set to `true`. This is because the behavior of this attribute is similar to the value of the `"$?"` expression common in UNIX interpreters. For example, this:
+
+ ```ruby
+ powershell_script 'make_safe_backup' do
+ guard_interpreter :powershell_script
+ code 'cp ~/data/nodes.json ~/data/nodes.bak'
+ not_if 'test-path ~/data/nodes.bak'
+ end
+ ```
+
+ is similar to:
+ ```ruby
+ bash 'make_safe_backup' do
+ code 'cp ~/data/nodes.json ~/data/nodes.bak'
+ not_if 'test -e ~/data/nodes.bak'
+ end
+ ```
+ DESC
+
description "Use the **powershell_script** resource to execute a script using the Windows PowerShell"\
" interpreter, much like how the script and script-based resources—bash, csh, perl, python,"\
" and ruby—are used. The powershell_script is specific to the Microsoft Windows platform"\
@@ -52,15 +76,6 @@ class Chef
super
@interpreter = "powershell.exe"
@default_guard_interpreter = resource_name
- @convert_boolean_return = false
- end
-
- def convert_boolean_return(arg = nil)
- set_or_return(
- :convert_boolean_return,
- arg,
- kind_of: [ FalseClass, TrueClass ]
- )
end
# Allow callers evaluating guards to request default