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.
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
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
|
# File 'lib/kafo/kafo_configure.rb', line 44
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.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def app_options
@app_options
end
|
.check_dirs ⇒ Object
Returns the value of attribute check_dirs.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def check_dirs
@check_dirs
end
|
.config ⇒ Object
Returns the value of attribute config.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def config
@config
end
|
.config_file ⇒ Object
Returns the value of attribute config_file.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def config_file
@config_file
end
|
.exit_handler ⇒ Object
Returns the value of attribute exit_handler.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def exit_handler
@exit_handler
end
|
.gem_root ⇒ Object
Returns the value of attribute gem_root.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def gem_root
@gem_root
end
|
.hooking ⇒ Object
39
40
41
|
# File 'lib/kafo/kafo_configure.rb', line 39
def hooking
@hooking ||= Hooking.new
end
|
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def kafo_modules_dir
@kafo_modules_dir
end
|
.logger ⇒ Object
Returns the value of attribute logger.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def logger
@logger
end
|
.module_dirs ⇒ Object
Returns the value of attribute module_dirs.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def module_dirs
@module_dirs
end
|
.root_dir ⇒ Object
Returns the value of attribute root_dir.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def root_dir
@root_dir
end
|
.scenario_manager ⇒ Object
Returns the value of attribute scenario_manager.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def scenario_manager
@scenario_manager
end
|
.verbose ⇒ Object
Returns the value of attribute verbose.
34
35
36
|
# File 'lib/kafo/kafo_configure.rb', line 34
def verbose
@verbose
end
|
Class Method Details
.app_option(*args, &block) ⇒ Object
181
182
183
184
185
|
# File 'lib/kafo/kafo_configure.rb', line 181
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
153
154
155
|
# File 'lib/kafo/kafo_configure.rb', line 153
def self.exit(code, &block)
exit_handler.exit(code, &block)
end
|
.exit_code ⇒ Object
157
158
159
|
# File 'lib/kafo/kafo_configure.rb', line 157
def self.exit_code
self.exit_handler.exit_code
end
|
.help(*args) ⇒ Object
174
175
176
177
178
179
|
# File 'lib/kafo/kafo_configure.rb', line 174
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
161
162
163
|
# File 'lib/kafo/kafo_configure.rb', line 161
def self.in_help_mode?
ARGV.include?('--help') || ARGV.include?('--full-help') || ARGV.include?('-h')
end
|
.run ⇒ Object
147
148
149
150
151
|
# File 'lib/kafo/kafo_configure.rb', line 147
def self.run
return super
rescue SystemExit => e
self.exit_handler.exit(self.exit_code) end
|
Instance Method Details
#add_module(name) ⇒ Object
199
200
201
202
203
|
# File 'lib/kafo/kafo_configure.rb', line 199
def add_module(name)
config.add_module(name)
reset_params_cache
self.module(name)
end
|
#config ⇒ Object
101
102
103
|
# File 'lib/kafo/kafo_configure.rb', line 101
def config
self.class.config
end
|
#execute ⇒ Object
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
|
# File 'lib/kafo/kafo_configure.rb', line 109
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
165
166
167
|
# File 'lib/kafo/kafo_configure.rb', line 165
def exit_code
self.class.exit_code
end
|
#help ⇒ Object
170
171
172
|
# File 'lib/kafo/kafo_configure.rb', line 170
def help
self.class.help(invocation_path, self)
end
|
#logger ⇒ Object
105
106
107
|
# File 'lib/kafo/kafo_configure.rb', line 105
def logger
self.class.logger
end
|
#module(name) ⇒ Object
209
210
211
|
# File 'lib/kafo/kafo_configure.rb', line 209
def module(name)
modules.detect { |m| m.name == name }
end
|
#modules ⇒ Object
205
206
207
|
# File 'lib/kafo/kafo_configure.rb', line 205
def modules
config.modules.sort
end
|
#param(mod, name) ⇒ Object
213
214
215
|
# File 'lib/kafo/kafo_configure.rb', line 213
def param(mod, name)
config.param(mod, name)
end
|
#params ⇒ Object
187
188
189
190
191
192
|
# File 'lib/kafo/kafo_configure.rb', line 187
def params
@params ||= modules.map(&:params).flatten
rescue KafoParsers::ModuleName => e
puts e
self.class.exit(:unknown_module)
end
|
#request_config_reload ⇒ Object
217
218
219
|
# File 'lib/kafo/kafo_configure.rb', line 217
def request_config_reload
@config_reload_requested = true
end
|
#reset_params_cache ⇒ Object
194
195
196
197
|
# File 'lib/kafo/kafo_configure.rb', line 194
def reset_params_cache
@params = nil
params
end
|