Method: Kafo::KafoConfigure#initialize

Defined in:
lib/kafo/kafo_configure.rb

#initialize(*args) ⇒ KafoConfigure

Returns a new instance of KafoConfigure.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kafo/kafo_configure.rb', line 101

def initialize(*args)
  self.class.preset_color_scheme
  self.class.logger           = Logger.new
  self.class.exit_handler     = ExitHandler.new
  @progress_bar               = nil
  @config_reload_requested    = false

  scenario_manager = setup_scenario_manager
  self.class.scenario_manager = scenario_manager

  # Handle --list-scenarios before we need them
  scenario_manager.list_available_scenarios if ARGV.include?('--list-scenarios')
  scenario_manager.check_enable_scenario
  scenario_manager.check_disable_scenario
  setup_config(config_file)

  self.class.hooking.execute(:pre_migrations)
  reload_config
  applied_total = self.class.config.run_migrations
  request_config_reload if applied_total > 0

  if ARGV.include?('--migrations-only')
    verbose = ARGV.include?('--verbose') || ARGV.include?('-v')
    Logging.setup(verbose: verbose)
    self.class.logger.notice('Log buffers flushed')
    self.class.exit(0)
  end

  reload_config

  if scenario_manager.configured?
    scenario_manager.check_scenario_change(self.class.config_file)
    if scenario_manager.scenario_changed?(self.class.config_file) && !self.class.in_help_mode?
      prev_config = scenario_manager.load_configuration(scenario_manager.previous_scenario)
      prev_config.run_migrations
      self.class.config.migrate_configuration(prev_config, :skip => [:log_name])
      setup_config(self.class.config_file)
      self.class.logger.notice("Due to scenario change the configuration (#{self.class.config_file}) was updated with #{scenario_manager.previous_scenario} and reloaded.")
    end
  end

  super

  self.class.hooking.execute(:boot)
  set_app_options # define args for installer
  # 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 # set values from ARGS to config.app

  if ARGV.any? { |option| ['--help', '--full-help'].include? option }
    Logging.setup_verbose(level: :error)
  else
    Logging.setup(verbose: config.app[:verbose])
  end

  logger.notice("Loading installer configuration. This will take some time.")
  self.class.set_color_scheme

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