Module: CovLoupe::Scripts::CommandExecution
- Included in:
- LatestCiStatus, PreReleaseCheck, SetupDocServer, StartDocServer
- Defined in:
- lib/cov_loupe/scripts/command_execution.rb
Instance Method Summary collapse
-
#abort_with(message) ⇒ Object
Print an error message and exit with status 1.
-
#command_exists?(cmd) ⇒ Boolean
Check if a command exists in the system PATH.
-
#run_command(cmd, print_output: false, fail_on_error: true) ⇒ String
Execute a command and return its stdout.
-
#run_command_with_status(cmd) ⇒ Array<String, Boolean>
Execute a command and return stdout and success status.
Instance Method Details
#abort_with(message) ⇒ Object
Print an error message and exit with status 1.
35 36 37 38 |
# File 'lib/cov_loupe/scripts/command_execution.rb', line 35 def abort_with() warn "ERROR: #{}" exit 1 end |
#command_exists?(cmd) ⇒ Boolean
Check if a command exists in the system PATH.
41 42 43 44 45 46 |
# File 'lib/cov_loupe/scripts/command_execution.rb', line 41 def command_exists?(cmd) return true if File.exist?(cmd) && File.executable?(cmd) checker = Gem.win_platform? ? 'where' : 'which' system(checker, cmd, out: File::NULL, err: File::NULL) end |
#run_command(cmd, print_output: false, fail_on_error: true) ⇒ String
Execute a command and return its stdout.
15 16 17 18 19 20 21 |
# File 'lib/cov_loupe/scripts/command_execution.rb', line 15 def run_command(cmd, print_output: false, fail_on_error: true) if print_output run_streamed(cmd, fail_on_error: fail_on_error) else run_captured(cmd, fail_on_error: fail_on_error) end end |
#run_command_with_status(cmd) ⇒ Array<String, Boolean>
Execute a command and return stdout and success status.
27 28 29 30 31 32 |
# File 'lib/cov_loupe/scripts/command_execution.rb', line 27 def run_command_with_status(cmd) stdout, _stderr, status = capture_command(cmd) [stdout.strip, status.success?] rescue Errno::ENOENT ["Command not found: #{command_display(cmd)}", false] end |