Method: PDK::CLI::Exec::Command#execute!
- Defined in:
- lib/pdk/cli/exec/command.rb
#execute! ⇒ Hash[Symbol => Object]
Returns The result from executing the command :stdout => String : The result of STDOUT :stderr => String : The result of STDERR :exit_code => Integer : The exit code from the command :duration => Float : Number seconds it took to execute.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/pdk/cli/exec/command.rb', line 97 def execute! # Start spinning if configured. @spinner.auto_spin if @spinner # Set env for child process resolved_env_for_command.each { |k, v| @process.environment[k] = v } if [:module, :pwd].include?(context) require 'pdk/util' mod_root = PDK::Util.module_root unless mod_root @spinner.error if @spinner raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)') end if Dir.pwd == mod_root || context == :pwd run_process_in_clean_env! else Dir.chdir(mod_root) do run_process_in_clean_env! end end else run_process! end # Stop spinning when done (if configured). stop_spinner @stdout.rewind @stderr.rewind process_data = { stdout: @stdout.read, stderr: @stderr.read, exit_code: @process.exit_code, duration: @duration, } PDK.logger.debug _('STDOUT: %{output}') % { output: process_data[:stdout].empty? ? 'N/A' : "\n#{process_data[:stdout]}", } PDK.logger.debug _('STDERR: %{output}') % { output: process_data[:stderr].empty? ? 'N/A' : "\n#{process_data[:stderr]}", } process_data ensure @stdout.close @stderr.close end |