Class: Bcome::Command

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Command

Returns a new instance of Command.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/command.rb', line 7

def initialize(params)
  @command = params[:command]
  @instance = params[:instance]
  @bootstrap = params[:bootstrap]  # whether to run this in bootstrap mode or not
  @success_exit_codes = params[:success_exit_codes]

  @stdout = ""
  @stderr = ""
  @exit_code = nil
  @exit_signal = nil
end

Instance Attribute Details

#bootstrapObject

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def bootstrap
  @bootstrap
end

#commandObject (readonly)

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def command
  @command
end

#exit_codeObject

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def exit_code
  @exit_code
end

#exit_signal(data) ⇒ Object (readonly)

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def exit_signal
  @exit_signal
end

#instanceObject (readonly)

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def instance
  @instance
end

#stderrObject

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def stderr
  @stderr
end

#stdoutObject

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def stdout
  @stdout
end

#success_exit_codesObject (readonly)

Wraps a command. Convenient flex-point for logging etc



5
6
7
# File 'lib/command.rb', line 5

def success_exit_codes
  @success_exit_codes
end

Instance Method Details

#is_success?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/command.rb', line 44

def is_success?
  success_exit_codes.include?(exit_code.to_s)
end

#outputObject



39
40
41
42
# File 'lib/command.rb', line 39

def output
  command_output = is_success? ? @stdout : "Exit code: #{@exit_code}\n\nSTDERR: #{@stderr}"
  return "\n#{command_output}"
end

#pretty_resultObject



19
20
21
# File 'lib/command.rb', line 19

def pretty_result
  return is_success? ? "success".success : "failure".failure
end

#proxyObject



35
36
37
# File 'lib/command.rb', line 35

def proxy
  @bootstrap ? instance.proxy(true) : instance.proxy
end

#ssh_keysObject



31
32
33
# File 'lib/command.rb', line 31

def ssh_keys
  @bootstrap ? [instance.bootstrap_settings[:key]] : instance.keys
end

#ssh_userObject



23
24
25
# File 'lib/command.rb', line 23

def ssh_user
  @bootstrap ? instance.bootstrap_settings[:ssh_user] : instance.ssh_user
end