Class: R::BuildStep
Overview
Manages reporting build progress.
Instance Attribute Summary collapse
-
#cmd ⇒ Array<String>
The command to execute.
-
#desc ⇒ String
The verb describing this step.
-
#importance ⇒ Symbol
The command’s importance.
-
#out ⇒ String
The command output.
-
#status ⇒ Process::Status
The exit status of the command.
Instance Method Summary collapse
-
#format_cmd(cmd) ⇒ Object
Format the command.
-
#initialize(cmd = [], out = "", desc = "", status = 0) ⇒ BuildStep
constructor
Constructor.
-
#print ⇒ Object
Print the result.
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
#cmd ⇒ Array<String>
The command to execute.
213 214 215 |
# File 'lib/rub/r/command.rb', line 213 def cmd @cmd end |
#desc ⇒ String
The verb describing this step.
209 210 211 |
# File 'lib/rub/r/command.rb', line 209 def desc @desc end |
#importance ⇒ Symbol
The command’s importance.
225 226 227 |
# File 'lib/rub/r/command.rb', line 225 def importance @importance end |
#out ⇒ String
The command output.
217 218 219 |
# File 'lib/rub/r/command.rb', line 217 def out @out end |
#status ⇒ Process::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 ⇒ Object
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 |