Module: Command
- Defined in:
- lib/command.rb
Instance Method Summary collapse
- #array_message(arr) ⇒ Object
-
#exec_step(command, output = nil) ⇒ Object
executes command and exits if status != 0.
-
#execute_command(cmd) ⇒ Object
executes command and returns properly colored output.
- #output(msg) ⇒ Object
- #stop_if(check, msg, command = '') ⇒ Object
- #stop_unless(check, msg, command = '') ⇒ Object
- #symbol_message(s) ⇒ Object
Instance Method Details
#array_message(arr) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/command.rb', line 49 def (arr) case arr[0] when :wrong_args msg = arr[0] msg += "\n" msg += ' valore possibile: ' values = '[ ' + arr[1].join(' | ').yellow + ' ]' msg += values msg end end |
#exec_step(command, output = nil) ⇒ Object
executes command and exits if status != 0
7 8 9 10 11 12 13 14 15 |
# File 'lib/command.rb', line 7 def exec_step(command, output = nil) if output puts output else puts 'exec > '.green + command.to_s.yellow end `#{command}` exit($CHILD_STATUS.exitstatus) unless $CHILD_STATUS.exitstatus.zero? end |
#execute_command(cmd) ⇒ Object
executes command and returns properly colored output
66 67 68 69 70 71 72 |
# File 'lib/command.rb', line 66 def execute_command(cmd) output "Eseguo #{cmd}".yellow res = `#{cmd}` color = $CHILD_STATUS.exitstatus.zero? ? 'green' : 'red' output res.send color stop_if (color == 'red'), "Errore durante la build dell'artifact".red end |
#output(msg) ⇒ Object
17 18 19 |
# File 'lib/command.rb', line 17 def output(msg) puts 'twig binaries > '.black + msg end |
#stop_if(check, msg, command = '') ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/command.rb', line 21 def stop_if(check, msg, command = '') if check output_msg = case msg when Symbol msg when Array msg else msg end command.empty? || exec(command) puts 'there was a problem > '.red + output_msg exit(1) end end |
#stop_unless(check, msg, command = '') ⇒ Object
61 62 63 |
# File 'lib/command.rb', line 61 def stop_unless(check, msg, command = '') stop_if !check, msg, command end |
#symbol_message(s) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/command.rb', line 38 def (s) case s when :clean 'hai dei file non committati...non posso continuare' when :detached_head "repo in stato 'head detached'" when :wrong_args 'argomento non corretto' end end |