From e258096e8b1452263a7c89031e4ec94d2e0c323e Mon Sep 17 00:00:00 2001 From: Pete Higgins Date: Thu, 28 May 2020 17:37:18 -0700 Subject: Untangle some inheritance code around script code. Signed-off-by: Pete Higgins --- lib/chef/provider/powershell_script.rb | 14 +++++--------- lib/chef/provider/script.rb | 9 +-------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 4f77cd2593..196bb3cd6f 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -26,11 +26,6 @@ class Chef provides :powershell_script - def initialize(*args) - super - add_exit_status_wrapper - end - action :run do validate_script_syntax! super() @@ -53,12 +48,11 @@ class Chef protected - # Process exit codes are strange with PowerShell and require - # special handling to cover common use cases. - def add_exit_status_wrapper - self.code = wrapper_script + def code + code = wrapper_script logger.trace("powershell_script provider called with script code:\n\n#{new_resource.code}\n") logger.trace("powershell_script provider will execute transformed code:\n\n#{code}\n") + code end def validate_script_syntax! @@ -99,6 +93,8 @@ class Chef end end + # Process exit codes are strange with PowerShell and require + # special handling to cover common use cases. # A wrapper script is used to launch user-supplied script while # still obtaining useful process exit codes. Unless you # explicitly call exit in PowerShell, the powershell.exe diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb index cccb79dfc0..cb4fcd8a22 100644 --- a/lib/chef/provider/script.rb +++ b/lib/chef/provider/script.rb @@ -34,14 +34,7 @@ class Chef provides :ruby provides :script - def_delegators :new_resource, :interpreter, :flags - - attr_accessor :code - - def initialize(new_resource, run_context) - super - self.code = new_resource.code - end + def_delegators :new_resource, :interpreter, :flags, :code def command "\"#{interpreter}\" #{flags} \"#{script_file.path}\"" -- cgit v1.2.1