summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrishichawda <rishichawda@users.noreply.github.com>2021-09-30 14:28:33 +0000
committerLamont Granquist <lamont@scriptkiddie.org>2021-11-03 16:50:59 -0700
commit0f05bdb6b38135447811e6d1aaed09d5c456d774 (patch)
tree74393936c219ec632dabf707b945b770597a6eef
parent924bfbff0bb82cc1ab51d4a03d71ad8dda2b65b1 (diff)
downloadchef-0f05bdb6b38135447811e6d1aaed09d5c456d774.tar.gz
update powershell_exec mixin
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
-rw-r--r--lib/chef/mixin/powershell_exec.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/chef/mixin/powershell_exec.rb b/lib/chef/mixin/powershell_exec.rb
index bbf8ae1a69..1975b36155 100644
--- a/lib/chef/mixin/powershell_exec.rb
+++ b/lib/chef/mixin/powershell_exec.rb
@@ -104,13 +104,15 @@ class Chef
#
# @param script [String] script to run
# @param interpreter [Symbol] the interpreter type, `:powershell` or `:pwsh`
+ # @param timeout [Integer, nil] timeout in seconds.
# @return [Chef::PowerShell] output
- def powershell_exec(script, interpreter = :powershell)
- case interpreter
+ def powershell_exec(script, options = {})
+ timeout = options.fetch(:timeout, nil)
+ case options.fetch(:interpreter, :powershell)
when :powershell
- Chef::PowerShell.new(script)
+ Chef::PowerShell.new(script, timeout: timeout)
when :pwsh
- Chef::Pwsh.new(script)
+ Chef::Pwsh.new(script, timeout: timeout)
else
raise ArgumentError, "Expected interpreter of :powershell or :pwsh"
end
@@ -118,8 +120,8 @@ class Chef
# The same as the #powershell_exec method except this will raise
# Chef::PowerShell::CommandFailed if the command fails
- def powershell_exec!(script, interpreter = :powershell)
- cmd = powershell_exec(script, interpreter)
+ def powershell_exec!(script, options = {})
+ cmd = powershell_exec(script, options)
cmd.error!
cmd
end