Class: ExecuteLocal

Inherits:
ExecuteBase show all
Defined in:
lib/teuton/case/execute/execute_local.rb

Instance Method Summary collapse

Methods inherited from ExecuteBase

#initialize

Methods included from Verbose

#verbose, #verboseln

Constructor Details

This class inherits a constructor from ExecuteBase

Instance Method Details

#callObject



8
9
10
11
12
13
# File 'lib/teuton/case/execute/execute_local.rb', line 8

def call
  action[:conn_type] = :local
  response = my_execute(action[:command], action[:encoding])
  result.exitcode = response[:exitcode]
  result.content = response[:content]
end

#my_execute(cmd, encoding = "UTF-8") ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/teuton/case/execute/execute_local.rb', line 15

def my_execute(cmd, encoding = "UTF-8")
  return {exitcode: 0, content: ""} if Project.debug?

  begin
    text, status = Open3.capture2e(cmd)
    exitcode = status.exitstatus
  rescue => e
    verbose Rainbow("!").green
    text = e.to_s
    exitcode = 1
  end
  content = encode_and_split(encoding, text)
  {exitcode: exitcode, content: content}
end