Class: Clinode::Command::Shell

Inherits:
String
  • Object
show all
Defined in:
lib/clinode/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*command) ⇒ Shell

Returns a new instance of Shell.



71
72
73
# File 'lib/clinode/command.rb', line 71

def initialize(*command)
  @command = command
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



68
69
70
# File 'lib/clinode/command.rb', line 68

def error
  @error
end

#outObject (readonly)

Returns the value of attribute out.



69
70
71
# File 'lib/clinode/command.rb', line 69

def out
  @out
end

Instance Method Details

#commandObject



90
91
92
# File 'lib/clinode/command.rb', line 90

def command
  @command.join(' ')
end

#error?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/clinode/command.rb', line 94

def error?
  !!@error
end

#out?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/clinode/command.rb', line 98

def out?
  !!@out
end

#runObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/clinode/command.rb', line 75

def run
  Clinode.debug "sh: #{command}"

  out = err = nil
  Open3.popen3(*@command) do |_, pout, perr|
    out = pout.read.strip
    err = perr.read.strip
  end

  replace @error = err unless err.empty?
  replace @out = out unless out.empty?

  self
end