Module: Fanforce::CLI::Utils

Extended by:
Utils
Included in:
Fanforce::CLI, Utils
Defined in:
lib/fanforce/cli/utils.rb

Instance Method Summary collapse

Instance Method Details

#confirm(msg) ⇒ Object



38
39
40
41
42
43
# File 'lib/fanforce/cli/utils.rb', line 38

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

#env(environment) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fanforce/cli/utils.rb', line 45

def env(environment)
  return if environment.blank?
  is_symbol = environment.is_a?(Symbol)
  env = case environment.to_sym
          when :development then :dev
          when :staging then :stg
          when :production then :prd
          else raise 'unknown environment'
        end
  is_symbol ? env : env.to_s
end

#error(msg, command = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fanforce/cli/utils.rb', line 25

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

#format(text, *args) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/fanforce/cli/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/cli/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

#get_heroku_app_name(app, environment) ⇒ Object



57
58
59
60
61
62
# File 'lib/fanforce/cli/utils.rb', line 57

def get_heroku_app_name(app, environment)
  raise 'unknown environment' if ![:production, :staging].include?(environment)

  heroku_app_name = "#{env(environment)}-#{app.dir_name}"
  heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name
end

#unknownObject



18
19
20
21
22
23
# File 'lib/fanforce/cli/utils.rb', line 18

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