Class: KubeDeployTools::Shellrunner
- Extended by:
- Forwardable
- Defined in:
- lib/kube_deploy_tools/shellrunner.rb
Class Attribute Summary collapse
-
.shellrunner ⇒ Object
Returns the value of attribute shellrunner.
Instance Method Summary collapse
- #check_call(*cmd, **opts) ⇒ Object
-
#initialize ⇒ Shellrunner
constructor
A new instance of Shellrunner.
- #run_call(*cmd, **opts) ⇒ Object
Constructor Details
#initialize ⇒ Shellrunner
Returns a new instance of Shellrunner.
16 17 |
# File 'lib/kube_deploy_tools/shellrunner.rb', line 16 def initialize end |
Class Attribute Details
.shellrunner ⇒ Object
Returns the value of attribute shellrunner.
12 13 14 |
# File 'lib/kube_deploy_tools/shellrunner.rb', line 12 def shellrunner @shellrunner end |
Instance Method Details
#check_call(*cmd, **opts) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/kube_deploy_tools/shellrunner.rb', line 19 def check_call(*cmd, **opts) out, err, status = run_call(*cmd, **opts) if !status.success? raise "Command failed: #{Shellwords.join(cmd)} with the following error: #{err}" end out end |
#run_call(*cmd, **opts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kube_deploy_tools/shellrunner.rb', line 27 def run_call(*cmd, **opts) print_cmd = opts.fetch(:print_cmd, true) if print_cmd Logger.info(Shellwords.join(cmd)) else Logger.debug(Shellwords.join(cmd)) end out, err, status = Open3.capture3(*cmd, stdin_data: opts[:stdin_data]) Logger.debug(out.shellescape) if !status.success? && print_cmd Logger.warn("The following command failed: #{Shellwords.join(cmd)}") Logger.warn(err) end [out.chomp, err.chomp, status] end |