Class: Pantry::Exec::Command

Inherits:
Command
  • Object
show all
Defined in:
lib/pantry/exec/command.rb

Overview

Execute a Shell command, returning STDOUT, STDERR, and the status code. Executes as the user the Pantry Client is running under.

Instance Method Summary collapse

Constructor Details

#initialize(*command_and_args) ⇒ Command

Returns a new instance of Command.



13
14
15
# File 'lib/pantry/exec/command.rb', line 13

def initialize(*command_and_args)
  @command_and_args = command_and_args
end

Instance Method Details

#perform(message) ⇒ Object



23
24
25
26
27
# File 'lib/pantry/exec/command.rb', line 23

def perform(message)
  command_and_args       = message.body[0]
  stdout, stderr, status = Open3.capture3(*command_and_args)
  [stdout, stderr, status.to_i]
end

#receive_client_response(response) ⇒ Object



29
30
31
32
33
34
# File 'lib/pantry/exec/command.rb', line 29

def receive_client_response(response)
  stdout, stderr, status = response.body
  Pantry.ui.say("From #{response.from}")
  Pantry.ui.say(stdout)
  Pantry.ui.say(stderr)
end

#to_messageObject



17
18
19
20
21
# File 'lib/pantry/exec/command.rb', line 17

def to_message
  message = super
  message << @command_and_args
  message
end