diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-05-07 11:46:24 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-05-07 12:04:32 -0700 |
commit | a8198cc042869b34937873db8f371cff77748f33 (patch) | |
tree | 67fddca3b3ddf7171c0b8133bad0ca2a88d2e05d /lib/chef/mixin | |
parent | 4056be318fa7aaddd46fff0f7fc15a7fd587d77b (diff) | |
download | chef-a8198cc042869b34937873db8f371cff77748f33.tar.gz |
Target mode code tweakslcg/target-mode-tweaks
The train_or_shell mixin should mixin its dependent mixins and
require them, which removes the need to do that in the calling classes.
Include TrainOrShell correctly in the Universal DSL.
Few more code tweaks ("protected" is largely worthless in ruby and was
always being misused here).
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/train_or_shell.rb | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/chef/mixin/train_or_shell.rb b/lib/chef/mixin/train_or_shell.rb index c976094b14..6a47d52a1d 100644 --- a/lib/chef/mixin/train_or_shell.rb +++ b/lib/chef/mixin/train_or_shell.rb @@ -17,20 +17,16 @@ # require "ostruct" +require "chef/mixin/shell_out" +require "chef/mixin/powershell_out" +require "chef/config" class Chef module Mixin module TrainOrShell - # - # Train #run_command returns a Train::Extras::CommandResult which - # includes `exit_status` but Mixlib::Shellout returns exitstatus - # This wrapper makes the result look like Mixlib::ShellOut to make it - # easier to swap providers from #shell_out to #train_or_shell - # - def train_to_shellout_result(stdout, stderr, exit_status) - status = OpenStruct.new(success?: ( exit_status == 0 )) - OpenStruct.new(stdout: stdout, stderr: stderr, exitstatus: exit_status, status: status) - end + + include Chef::Mixin::ShellOut + include Chef::Mixin::PowershellOut def train_or_shell(*args, **opts) if Chef::Config.target_mode? @@ -69,6 +65,19 @@ class Chef powershell_out!(*args) end end + + private + + # + # Train #run_command returns a Train::Extras::CommandResult which + # includes `exit_status` but Mixlib::Shellout returns exitstatus + # This wrapper makes the result look like Mixlib::ShellOut to make it + # easier to swap providers from #shell_out to #train_or_shell + # + def train_to_shellout_result(stdout, stderr, exit_status) + status = OpenStruct.new(success?: ( exit_status == 0 )) + OpenStruct.new(stdout: stdout, stderr: stderr, exitstatus: exit_status, status: status) + end end end end |