Class: Kafo::KafoConfigure
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- Kafo::KafoConfigure
show all
- Includes:
- StringHelper
- Defined in:
- lib/kafo/kafo_configure.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#dashize, #parametrize, #underscore, #with_prefix
Constructor Details
Returns a new instance of KafoConfigure.
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
|
# File 'lib/kafo/kafo_configure.rb', line 47
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
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')
self.class.verbose = (ARGV.include?('--verbose') || ARGV.include?('-v'))
Logger.setup
self.class.logger.info('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.info("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 parse clamp_app_arguments
parse_app_arguments Logger.setup
self.class.set_color_scheme
self.class.hooking.execute(:init)
set_parameters set_options
end
|
Class Attribute Details
.app_options ⇒ Object
Returns the value of attribute app_options.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def app_options
@app_options
end
|
.check_dirs ⇒ Object
Returns the value of attribute check_dirs.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def check_dirs
@check_dirs
end
|
.config ⇒ Object
Returns the value of attribute config.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def config
@config
end
|
.config_file ⇒ Object
Returns the value of attribute config_file.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def config_file
@config_file
end
|
.exit_handler ⇒ Object
Returns the value of attribute exit_handler.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def exit_handler
@exit_handler
end
|
.gem_root ⇒ Object
Returns the value of attribute gem_root.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def gem_root
@gem_root
end
|
.hooking ⇒ Object
42
43
44
|
# File 'lib/kafo/kafo_configure.rb', line 42
def hooking
@hooking ||= Hooking.new
end
|
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def kafo_modules_dir
@kafo_modules_dir
end
|
.logger ⇒ Object
Returns the value of attribute logger.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def logger
@logger
end
|
.module_dirs ⇒ Object
Returns the value of attribute module_dirs.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def module_dirs
@module_dirs
end
|
.root_dir ⇒ Object
Returns the value of attribute root_dir.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def root_dir
@root_dir
end
|
.scenario_manager ⇒ Object
Returns the value of attribute scenario_manager.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def scenario_manager
@scenario_manager
end
|
.store ⇒ Object
Returns the value of attribute store.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def store
@store
end
|
.verbose ⇒ Object
Returns the value of attribute verbose.
37
38
39
|
# File 'lib/kafo/kafo_configure.rb', line 37
def verbose
@verbose
end
|
Class Method Details
.app_option(*args, &block) ⇒ Object
196
197
198
199
200
|
# File 'lib/kafo/kafo_configure.rb', line 196
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
168
169
170
|
# File 'lib/kafo/kafo_configure.rb', line 168
def self.exit(code, &block)
exit_handler.exit(code, &block)
end
|
.exit_code ⇒ Object
172
173
174
|
# File 'lib/kafo/kafo_configure.rb', line 172
def self.exit_code
self.exit_handler.exit_code
end
|
.help(*args) ⇒ Object
189
190
191
192
193
194
|
# File 'lib/kafo/kafo_configure.rb', line 189
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
|
.in_help_mode? ⇒ Boolean
176
177
178
|
# File 'lib/kafo/kafo_configure.rb', line 176
def self.in_help_mode?
ARGV.include?('--help') || ARGV.include?('--full-help') || ARGV.include?('-h')
end
|
.run ⇒ Object
162
163
164
165
166
|
# File 'lib/kafo/kafo_configure.rb', line 162
def self.run
return super
rescue SystemExit => e
self.exit_handler.exit(self.exit_code) end
|
Instance Method Details
#add_module(name) ⇒ Object
218
219
220
221
222
|
# File 'lib/kafo/kafo_configure.rb', line 218
def add_module(name)
config.add_module(name)
reset_params_cache
self.module(name)
end
|
#config ⇒ Object
104
105
106
|
# File 'lib/kafo/kafo_configure.rb', line 104
def config
self.class.config
end
|
#enabled_params ⇒ Object
209
210
211
|
# File 'lib/kafo/kafo_configure.rb', line 209
def enabled_params
params.select { |p| p.module.enabled? }
end
|
#execute ⇒ Object
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
|
# File 'lib/kafo/kafo_configure.rb', line 124
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 skip_checks_i_know_better?
unless SystemChecker.check
puts "Your system does not meet configuration criteria"
self.class.exit(:invalid_system)
end
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
self.class.hooking.execute(:pre_commit)
unless dont_save_answers? || noop?
store_params
self.class.scenario_manager.link_last_scenario(self.class.config_file) if self.class.scenario_manager.configured?
end
run_installation
return self
rescue SystemExit
return self
end
|
#exit_code ⇒ Object
180
181
182
|
# File 'lib/kafo/kafo_configure.rb', line 180
def exit_code
self.class.exit_code
end
|
#help ⇒ Object
185
186
187
|
# File 'lib/kafo/kafo_configure.rb', line 185
def help
self.class.help(invocation_path, self)
end
|
#logger ⇒ Object
112
113
114
|
# File 'lib/kafo/kafo_configure.rb', line 112
def logger
self.class.logger
end
|
#module(name) ⇒ Object
228
229
230
|
# File 'lib/kafo/kafo_configure.rb', line 228
def module(name)
modules.detect { |m| m.name == name }
end
|
#modules ⇒ Object
224
225
226
|
# File 'lib/kafo/kafo_configure.rb', line 224
def modules
config.modules.sort
end
|
#param(mod, name) ⇒ Object
232
233
234
|
# File 'lib/kafo/kafo_configure.rb', line 232
def param(mod, name)
config.param(mod, name)
end
|
#params ⇒ Object
202
203
204
205
206
207
|
# File 'lib/kafo/kafo_configure.rb', line 202
def params
@params ||= modules.map(&:params).flatten
rescue KafoParsers::ModuleName => e
puts e
self.class.exit(:unknown_module)
end
|
#request_config_reload ⇒ Object
236
237
238
|
# File 'lib/kafo/kafo_configure.rb', line 236
def request_config_reload
@config_reload_requested = true
end
|
#reset_params_cache ⇒ Object
213
214
215
216
|
# File 'lib/kafo/kafo_configure.rb', line 213
def reset_params_cache
@params = nil
params
end
|
#run(*args) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/kafo/kafo_configure.rb', line 116
def run(*args)
started_at = Time.now
logger.info("Running installer with args #{args.inspect}")
super
ensure
logger.info("Installer finished in #{Time.now - started_at} seconds")
end
|
#store ⇒ Object
108
109
110
|
# File 'lib/kafo/kafo_configure.rb', line 108
def store
self.class.store
end
|