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.
46
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
|
# File 'lib/kafo/kafo_configure.rb', line 46
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.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def app_options
@app_options
end
|
.check_dirs ⇒ Object
Returns the value of attribute check_dirs.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def check_dirs
@check_dirs
end
|
.config ⇒ Object
Returns the value of attribute config.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def config
@config
end
|
.config_file ⇒ Object
Returns the value of attribute config_file.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def config_file
@config_file
end
|
.exit_handler ⇒ Object
Returns the value of attribute exit_handler.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def exit_handler
@exit_handler
end
|
.gem_root ⇒ Object
Returns the value of attribute gem_root.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def gem_root
@gem_root
end
|
.hooking ⇒ Object
41
42
43
|
# File 'lib/kafo/kafo_configure.rb', line 41
def hooking
@hooking ||= Hooking.new
end
|
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def kafo_modules_dir
@kafo_modules_dir
end
|
.logger ⇒ Object
Returns the value of attribute logger.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def logger
@logger
end
|
.module_dirs ⇒ Object
Returns the value of attribute module_dirs.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def module_dirs
@module_dirs
end
|
.root_dir ⇒ Object
Returns the value of attribute root_dir.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def root_dir
@root_dir
end
|
.scenario_manager ⇒ Object
Returns the value of attribute scenario_manager.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def scenario_manager
@scenario_manager
end
|
.store ⇒ Object
Returns the value of attribute store.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def store
@store
end
|
.verbose ⇒ Object
Returns the value of attribute verbose.
36
37
38
|
# File 'lib/kafo/kafo_configure.rb', line 36
def verbose
@verbose
end
|
Class Method Details
.app_option(*args, &block) ⇒ Object
195
196
197
198
199
|
# File 'lib/kafo/kafo_configure.rb', line 195
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
167
168
169
|
# File 'lib/kafo/kafo_configure.rb', line 167
def self.exit(code, &block)
exit_handler.exit(code, &block)
end
|
.exit_code ⇒ Object
171
172
173
|
# File 'lib/kafo/kafo_configure.rb', line 171
def self.exit_code
self.exit_handler.exit_code
end
|
.help(*args) ⇒ Object
188
189
190
191
192
193
|
# File 'lib/kafo/kafo_configure.rb', line 188
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
175
176
177
|
# File 'lib/kafo/kafo_configure.rb', line 175
def self.in_help_mode?
ARGV.include?('--help') || ARGV.include?('--full-help') || ARGV.include?('-h')
end
|
.run ⇒ Object
161
162
163
164
165
|
# File 'lib/kafo/kafo_configure.rb', line 161
def self.run
return super
rescue SystemExit
self.exit_handler.exit(self.exit_code) end
|
Instance Method Details
#add_module(name) ⇒ Object
217
218
219
220
221
|
# File 'lib/kafo/kafo_configure.rb', line 217
def add_module(name)
config.add_module(name)
reset_params_cache
self.module(name)
end
|
#config ⇒ Object
103
104
105
|
# File 'lib/kafo/kafo_configure.rb', line 103
def config
self.class.config
end
|
#enabled_params ⇒ Object
208
209
210
|
# File 'lib/kafo/kafo_configure.rb', line 208
def enabled_params
params.select { |p| p.module.enabled? }
end
|
#execute ⇒ Object
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
|
# File 'lib/kafo/kafo_configure.rb', line 123
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
179
180
181
|
# File 'lib/kafo/kafo_configure.rb', line 179
def exit_code
self.class.exit_code
end
|
#help ⇒ Object
184
185
186
|
# File 'lib/kafo/kafo_configure.rb', line 184
def help
self.class.help(invocation_path, self)
end
|
#logger ⇒ Object
111
112
113
|
# File 'lib/kafo/kafo_configure.rb', line 111
def logger
self.class.logger
end
|
#module(name) ⇒ Object
227
228
229
|
# File 'lib/kafo/kafo_configure.rb', line 227
def module(name)
modules.detect { |m| m.name == name }
end
|
#modules ⇒ Object
223
224
225
|
# File 'lib/kafo/kafo_configure.rb', line 223
def modules
config.modules.sort
end
|
#param(mod, name) ⇒ Object
231
232
233
|
# File 'lib/kafo/kafo_configure.rb', line 231
def param(mod, name)
config.param(mod, name)
end
|
#params ⇒ Object
201
202
203
204
205
206
|
# File 'lib/kafo/kafo_configure.rb', line 201
def params
@params ||= modules.map(&:params).flatten
rescue KafoParsers::ModuleName => e
puts e
self.class.exit(:unknown_module)
end
|
#request_config_reload ⇒ Object
235
236
237
|
# File 'lib/kafo/kafo_configure.rb', line 235
def request_config_reload
@config_reload_requested = true
end
|
#reset_params_cache ⇒ Object
212
213
214
215
|
# File 'lib/kafo/kafo_configure.rb', line 212
def reset_params_cache
@params = nil
params
end
|
#run(*args) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/kafo/kafo_configure.rb', line 115
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
107
108
109
|
# File 'lib/kafo/kafo_configure.rb', line 107
def store
self.class.store
end
|