Module: Command
- Defined in:
- lib/command.rb
Instance Method Summary collapse
- #array_message(arr) ⇒ Object
-
#execute_command(cmd) ⇒ Object
executes command and returns properly colored output.
- #output(msg) ⇒ Object
- #stop_if(check, msg, command = '') ⇒ Object
- #symbol_message(s) ⇒ Object
Instance Method Details
#array_message(arr) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/command.rb', line 38 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 |
#execute_command(cmd) ⇒ Object
executes command and returns properly colored output
51 52 53 54 55 56 57 |
# File 'lib/command.rb', line 51 def execute_command(cmd) output "Executing #{cmd}".yellow res = `#{cmd}` color = $CHILD_STATUS.exitstatus.zero? ? 'green' : 'red' output res.send color stop_if (color == 'red'), 'Error'.red end |
#output(msg) ⇒ Object
6 7 8 |
# File 'lib/command.rb', line 6 def output(msg) puts 'twig binaries > '.black + msg end |
#stop_if(check, msg, command = '') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/command.rb', line 10 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 |
#symbol_message(s) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/command.rb', line 27 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 |