Class: Botiasloop::Tools::Shell

Inherits:
Botiasloop::Tool show all
Defined in:
lib/botiasloop/tools/shell.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Methods inherited from Botiasloop::Tool

#name, tool_name

Instance Method Details

#execute(command:) ⇒ Hash

Execute a shell command

Parameters:

  • command (String)

    Shell command to execute

Returns:

  • (Hash)

    Result with stdout, stderr, exit_code, and success?

Raises:



17
18
19
20
21
22
23
24
# File 'lib/botiasloop/tools/shell.rb', line 17

def execute(command:)
  stdout, stderr, status = Open3.capture3(command)
  Result.new(stdout, stderr, status.exitstatus).to_h
rescue Errno::ENOENT => e
  raise Error, "Command not found: #{e.message}"
rescue Errno::EACCES => e
  raise Error, "Permission denied: #{e.message}"
end