Class: R::BuildStep

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

Overview

Manages reporting build progress.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd = [], out = "", desc = "", status = 0) ⇒ BuildStep

Constructor



250
251
252
253
254
255
256
257
258
# File 'lib/rub/r/command.rb', line 250

def initialize(cmd=[], out="", desc="", status=0)
  @cmd    = cmd
  @out    = out
  @desc   = desc
  @status = status
  
  # For some reason self is needed.
  self.importance = :high
end

Instance Attribute Details

#cmdArray<String>

The command to execute.



213
214
215
# File 'lib/rub/r/command.rb', line 213

def cmd
  @cmd
end

#descString

The verb describing this step.



209
210
211
# File 'lib/rub/r/command.rb', line 209

def desc
  @desc
end

#importanceSymbol

The command’s importance.



225
226
227
# File 'lib/rub/r/command.rb', line 225

def importance
  @importance
end

#outString

The command output.



217
218
219
# File 'lib/rub/r/command.rb', line 217

def out
  @out
end

#statusProcess::Status

The exit status of the command.



221
222
223
# File 'lib/rub/r/command.rb', line 221

def status
  @status
end

Instance Method Details

#format_cmd(cmd) ⇒ Object

Format the command.

Format’s the command in the prettiest way possible. Theoretically this command could be pasted into a shell and execute the desired command.



267
268
269
270
271
272
273
274
275
# File 'lib/rub/r/command.rb', line 267

def format_cmd(cmd)
  cmd.map do |e|
    if /[~`!#$&*(){};'"]/ =~ e
      "'#{e.sub(/['"]/, '\\\1')}'"
    else
      e
    end
  end.join(' ')
end

Print the result.



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/rub/r/command.rb', line 278

def print
  @importancei < 2 and return

  puts "\e[#{status==0 ? '' : '31;'}1m#{@desc}\e[0m"
  puts format_cmd @cmd unless @cmd.empty?
  Kernel::print @out
  
  if status != 0
    if cmd.empty?
      puts "\e[31;1mProcess failed.\e[0m"
    else
      puts "\e[31;1mProcess returned status #{status}\e[0m"
    end
  end
end