Module: Fanforce::Factory::Utils
Instance Method Summary collapse
- #confirm(msg) ⇒ Object
- #error(msg, command = nil) ⇒ Object
- #format(text, *args) ⇒ Object
- #format_config(hash) ⇒ Object
- #unknown ⇒ Object
Instance Method Details
#confirm(msg) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fanforce/factory/utils.rb', line 38 def confirm(msg) puts '---------------------------------------------------------------------------------------------------------------' print "#{msg} [y/n]: " input = $stdin.gets.strip exit 0 if input.downcase == 'n' end |
#error(msg, command = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fanforce/factory/utils.rb', line 25 def error(msg, command=nil) puts '---------------------------------------------------------------------------------------------------------------' puts 'ERROR... '.format(:bold,:red) + msg puts '---------------------------------------------------------------------------------------------------------------' puts '' if command.present? puts Fanforce::Factory::Help.for(command, @allowed_commands) else puts Fanforce::Factory::Help.commands(@allowed_commands) end exit 1 end |
#format(text, *args) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/fanforce/factory/utils.rb', line 4 def format(text, *args) effect = args.include?(:bold) ? 1 : 0 color = if args.include?(:red) then 31 elsif args.include?(:green) then 32 elsif args.include?(:magenta) then 35 else 39 end "\033[#{effect};#{color}m#{text}\033[0m" end |
#format_config(hash) ⇒ Object
13 14 15 16 |
# File 'lib/fanforce/factory/utils.rb', line 13 def format_config(hash) hash.values.select{|v| v.is_a? Hash}.each{|h| format_config(h)} hash.symbolize_keys! end |
#unknown ⇒ Object
18 19 20 21 22 23 |
# File 'lib/fanforce/factory/utils.rb', line 18 def unknown puts '---------------------------------------------------------------------------------------------------------------' puts 'OOPS'.format(:bold,:red) + '... unknown command'.format(:red) puts Fanforce::Factory::Help.commands(@allowed_commands) exit 1 end |