Sha256: 5000e657ac15ba6ab5f4e5174f6cbc33439e6368b8fd8a0bbce6a6f04a5cef75

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

module Fanforce::CLI::Utils
  extend Fanforce::CLI::Utils

  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

  def format_config(hash)
    hash.values.select{|v| v.is_a? Hash}.each{|h| format_config(h)}
    hash.symbolize_keys!
  end

  def unknown
    puts '---------------------------------------------------------------------------------------------------------------'
    puts 'OOPS'.format(:bold,:red) + '... unknown command'.format(:red)
    puts Fanforce::CLI::Help.commands(@allowed_commands)
    exit 1
  end

  def error(msg, command=nil)
    puts '---------------------------------------------------------------------------------------------------------------'
    puts 'ERROR... '.format(:bold,:red) + msg
    puts '---------------------------------------------------------------------------------------------------------------'
    puts ''
    if command.present?
      puts Fanforce::CLI::Help.for(command, @allowed_commands)
    else
      puts Fanforce::CLI::Help.commands(@allowed_commands)
    end
    exit 1
  end

  def confirm(msg)
    puts '---------------------------------------------------------------------------------------------------------------'
    print "#{msg} [y/n]: "
    input = $stdin.gets.strip
    exit 0 if input.downcase == 'n'
  end

end

class String
  def format(*args)
    Fanforce::CLI::Utils.format(self, *args)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fanforce-cli-1.6.0 lib/fanforce/cli/utils.rb
fanforce-cli-1.5.0 lib/fanforce/cli/utils.rb
fanforce-cli-1.4.0 lib/fanforce/cli/utils.rb
fanforce-cli-1.3.0 lib/fanforce/cli/utils.rb
fanforce-cli-1.2.0 lib/fanforce/cli/utils.rb
fanforce-cli-1.1.0 lib/fanforce/cli/utils.rb