class R::BuildStep
Manages reporting build progress.
Attributes
The command to execute. @return [Array<String>]
The verb describing this step. @return [String]
The command’s importance. @return [Symbol] :low, :medium or :high
The command output. @return [String]
The exit status of the command. @return [Process::Status]
Public Class Methods
Constructor
@param cmd [Array<String>] The command executed. @param out [String] The output generated. @param desc [String] A verb describing the event.
# 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
Public Instance Methods
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.
@param cmd [Array<String>] The command.
# 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
Set the command’s importance. @param i [Symbol] :low, :medium or :high @return [Symbol] i
# File lib/rub/r/command.rb, line 230 def importance=(i) @importance = i case i when :low @importancei = 1 when :med @importancei = 2 when :high @importancei = 3 else $stderr.puts "Unknown importance #{i.inspect}, defaulting to :high." @importancei = 3 end end
Print the result.
# 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