Class: Madness::Commands::Config

Inherits:
Base
  • Object
show all
Defined in:
lib/madness/commands/config.rb

Instance Method Summary collapse

Methods inherited from Base

#config

Instance Method Details

#new_commandObject

Raises:



13
14
15
16
17
18
# File 'lib/madness/commands/config.rb', line 13

def new_command
  raise InitError, "Configuration file #{config.filename} already exists" if File.exist? config.filename

  FileUtils.cp File.expand_path('../templates/madness.yml', __dir__), config.filename
  say "Created g`#{config.filename}` config file"
end

#show_commandObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/madness/commands/config.rb', line 20

def show_command
  errors_found = false

  config.data.each do |key, value|
    value_color = config.defaults[key] == value ? 'n' : 'bb'
    if config.defaults.has_key?(key)
      key_color = 'g'
    else
      key_color = 'r'
      value_color = 'r'
      errors_found = true
    end

    say "#{key_color}`#{key.to_s.rjust 20}`:  #{value_color}`#{value || '~'}`"
  end

  say ''

  if config.file_exist?
    say "Values in bb`blue` loaded from g`#{config.filename}`"
  end

  return unless errors_found

  say 'Keys in r`red` are not recognized'
end