Class: Kafo::KafoConfigure

Inherits:
Clamp::Command
  • Object
show all
Includes:
StringHelper
Defined in:
lib/kafo/kafo_configure.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StringHelper

#dashize, #parametrize, #underscore, #with_prefix

Constructor Details

#initialize(*args) ⇒ KafoConfigure

Returns a new instance of KafoConfigure.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/kafo/kafo_configure.rb', line 40

def initialize(*args)
  self.class.logger           = Logger.new
  self.class.exit_handler     = ExitHandler.new
  self.class.config_file      = config_file
  self.class.config           = Configuration.new(self.class.config_file)
  self.class.root_dir         = File.expand_path(self.class.config.app[:installer_dir])
  modules_dir                 = self.class.config.app[:modules_dir] || (self.class.config.app[:installer_dir] + '/modules')
  self.class.modules_dir      = File.expand_path(modules_dir)
  self.class.gem_root         = File.join(File.dirname(__FILE__), '../../')
  self.class.kafo_modules_dir = self.class.config.app[:kafo_modules_dir] || (self.class.gem_root + '/modules')
  @progress_bar               = nil
  self.class.hooking.load
  self.class.hooking.kafo     = self

  super

  self.class.hooking.execute(:boot)
  set_app_options
  # we need to parse app config params using clamp even before run method does it
  # so we limit parsing only to app config options (because of --help and later defined params)
  parse clamp_app_arguments
  parse_app_arguments
  Logger.setup
  ColorScheme.new(config).setup

  self.class.hooking.execute(:init)
  set_parameters # here the params gets parsed and we need app config populated
  set_options
end

Class Attribute Details

.app_optionsObject

Returns the value of attribute app_options.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def app_options
  @app_options
end

.configObject

Returns the value of attribute config.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def config
  @config
end

.config_fileObject

Returns the value of attribute config_file.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def config_file
  @config_file
end

.exit_handlerObject

Returns the value of attribute exit_handler.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def exit_handler
  @exit_handler
end

.gem_rootObject

Returns the value of attribute gem_root.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def gem_root
  @gem_root
end

.hookingObject



35
36
37
# File 'lib/kafo/kafo_configure.rb', line 35

def hooking
  @hooking ||= Hooking.new
end

.kafo_modules_dirObject

Returns the value of attribute kafo_modules_dir.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def kafo_modules_dir
  @kafo_modules_dir
end

.loggerObject

Returns the value of attribute logger.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def logger
  @logger
end

.modules_dirObject

Returns the value of attribute modules_dir.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def modules_dir
  @modules_dir
end

.root_dirObject

Returns the value of attribute root_dir.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def root_dir
  @root_dir
end

.temp_config_fileObject

Returns the value of attribute temp_config_file.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def temp_config_file
  @temp_config_file
end

.verboseObject

Returns the value of attribute verbose.



30
31
32
# File 'lib/kafo/kafo_configure.rb', line 30

def verbose
  @verbose
end

Class Method Details

.app_option(*args, &block) ⇒ Object



145
146
147
148
149
# File 'lib/kafo/kafo_configure.rb', line 145

def self.app_option(*args, &block)
  self.app_options ||= []
  self.app_options.push self.option(*args, &block)
  self.app_options.last
end

.exit(code, &block) ⇒ Object



121
122
123
# File 'lib/kafo/kafo_configure.rb', line 121

def self.exit(code, &block)
  exit_handler.exit(code, &block)
end

.exit_codeObject



125
126
127
# File 'lib/kafo/kafo_configure.rb', line 125

def self.exit_code
  self.exit_handler.exit_code
end

.help(*args) ⇒ Object



138
139
140
141
142
143
# File 'lib/kafo/kafo_configure.rb', line 138

def self.help(*args)
  kafo          = args.pop
  builder_class = kafo.full_help? ? HelpBuilders::Advanced : HelpBuilders::Basic
  args.push builder_class.new(kafo.params)
  super(*args)
end

.runObject



115
116
117
118
119
# File 'lib/kafo/kafo_configure.rb', line 115

def self.run
  return super
rescue SystemExit => e
  self.exit_handler.exit(self.exit_code) # fail in initialize
end

Instance Method Details

#add_module(name) ⇒ Object



163
164
165
166
167
# File 'lib/kafo/kafo_configure.rb', line 163

def add_module(name)
  config.add_module(name)
  reset_params_cache
  self.module(name)
end

#configObject



70
71
72
# File 'lib/kafo/kafo_configure.rb', line 70

def config
  self.class.config
end

#executeObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/kafo/kafo_configure.rb', line 78

def execute
  parse_cli_arguments

  if (self.class.verbose = !!verbose?)
    Logger.setup_verbose
  else
    @progress_bar = self.class.config.app[:colors] ? ProgressBars::Colored.new : ProgressBars::BlackWhite.new
  end

  unless SystemChecker.check
    puts "Your system does not meet configuration criteria"
    self.class.exit(:invalid_system)
  end

  self.class.hooking.execute(:pre_validations)
  if interactive?
    wizard = Wizard.new(self)
    wizard.run
  else
    unless validate_all
      puts "Error during configuration, exiting"
      self.class.exit(:invalid_values)
    end
  end

  if dont_save_answers?
    self.class.temp_config_file = temp_config_file
    store_params(temp_config_file)
  else
    store_params
  end
  run_installation
  return self
rescue SystemExit
  return self
end

#exit_codeObject



129
130
131
# File 'lib/kafo/kafo_configure.rb', line 129

def exit_code
  self.class.exit_code
end

#helpObject



134
135
136
# File 'lib/kafo/kafo_configure.rb', line 134

def help
  self.class.help(invocation_path, self)
end

#loggerObject



74
75
76
# File 'lib/kafo/kafo_configure.rb', line 74

def logger
  self.class.logger
end

#module(name) ⇒ Object



173
174
175
# File 'lib/kafo/kafo_configure.rb', line 173

def module(name)
  modules.detect { |m| m.name == name }
end

#modulesObject



169
170
171
# File 'lib/kafo/kafo_configure.rb', line 169

def modules
  config.modules.sort
end

#param(mod, name) ⇒ Object



177
178
179
# File 'lib/kafo/kafo_configure.rb', line 177

def param(mod, name)
  params.detect { |p| p.name == name && p.module.name == mod }
end

#paramsObject



151
152
153
154
155
156
# File 'lib/kafo/kafo_configure.rb', line 151

def params
  @params ||= modules.map(&:params).flatten
rescue KafoParsers::ModuleName => e
  puts e
  self.class.exit(:unknown_module)
end

#reset_params_cacheObject



158
159
160
161
# File 'lib/kafo/kafo_configure.rb', line 158

def reset_params_cache
  @params = nil
  params
end