Class: KafoConfigure
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- KafoConfigure
- Includes:
- StringHelper
- Defined in:
- lib/kafo/kafo_configure.rb
Class Attribute Summary collapse
-
.app_options ⇒ Object
Returns the value of attribute app_options.
-
.config ⇒ Object
Returns the value of attribute config.
-
.config_file ⇒ Object
Returns the value of attribute config_file.
-
.gem_root ⇒ Object
Returns the value of attribute gem_root.
-
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.modules_dir ⇒ Object
Returns the value of attribute modules_dir.
-
.root_dir ⇒ Object
Returns the value of attribute root_dir.
-
.temp_config_file ⇒ Object
Returns the value of attribute temp_config_file.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
- .app_option(*args, &block) ⇒ Object
- .exit(code) ⇒ Object
- .exit_code ⇒ Object
- .run ⇒ Object
- .translate_exit_code(code) ⇒ Object
Instance Method Summary collapse
- #config ⇒ Object
- #execute ⇒ Object
- #exit_code ⇒ Object
-
#initialize(*args) ⇒ KafoConfigure
constructor
A new instance of KafoConfigure.
- #module(name) ⇒ Object
- #modules ⇒ Object
- #param(mod, name) ⇒ Object
- #params ⇒ Object
Methods included from StringHelper
#dashize, #parametrize, #underscore, #with_prefix
Constructor Details
#initialize(*args) ⇒ KafoConfigure
Returns a new instance of KafoConfigure.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kafo/kafo_configure.rb', line 22 def initialize(*args) self.class.logger = Logger.new self.class.config_file = config_file self.class.config = Configuration.new(self.class.config_file) self.class.root_dir = File.(self.class.config.app[:installer_dir]) modules_dir = self.class.config.app[:module_dir] || (self.class.config.app[:installer_dir] + '/modules') self.class.modules_dir = File.(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 super allowed = self.class..map(&:switches).flatten allowed.map! { |s| s.include?('[no-]') ? [s.sub('[no-]', ''), s.sub('[no-]', 'no-')] : s }.flatten! # 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 ARGV.select { |a| a =~ /([a-zA-Z0-9_-]*)([= ].*)?/ && allowed.include?($1) } parse_app_arguments Logger.setup set_parameters # here the params gets parsed and we need app config populated end |
Class Attribute Details
.app_options ⇒ Object
Returns the value of attribute app_options.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def @app_options end |
.config ⇒ Object
Returns the value of attribute config.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def config @config end |
.config_file ⇒ Object
Returns the value of attribute config_file.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def config_file @config_file end |
.gem_root ⇒ Object
Returns the value of attribute gem_root.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def gem_root @gem_root end |
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def kafo_modules_dir @kafo_modules_dir end |
.logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def logger @logger end |
.modules_dir ⇒ Object
Returns the value of attribute modules_dir.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def modules_dir @modules_dir end |
.root_dir ⇒ Object
Returns the value of attribute root_dir.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def root_dir @root_dir end |
.temp_config_file ⇒ Object
Returns the value of attribute temp_config_file.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def temp_config_file @temp_config_file end |
.verbose ⇒ Object
Returns the value of attribute verbose.
18 19 20 |
# File 'lib/kafo/kafo_configure.rb', line 18 def verbose @verbose end |
Class Method Details
.app_option(*args, &block) ⇒ Object
123 124 125 126 127 |
# File 'lib/kafo/kafo_configure.rb', line 123 def self.app_option(*args, &block) self. ||= [] self..push self.option(*args, &block) self..last end |
.exit(code) ⇒ Object
99 100 101 102 |
# File 'lib/kafo/kafo_configure.rb', line 99 def self.exit(code) @exit_code = translate_exit_code(code) throw :exit end |
.exit_code ⇒ Object
104 105 106 |
# File 'lib/kafo/kafo_configure.rb', line 104 def self.exit_code @exit_code ||= 0 end |
.run ⇒ Object
88 89 90 91 92 93 |
# File 'lib/kafo/kafo_configure.rb', line 88 def self.run catch :exit do return super end Kernel.exit(self.exit_code) # fail in initialize end |
.translate_exit_code(code) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kafo/kafo_configure.rb', line 108 def self.translate_exit_code(code) return code if code.is_a? Fixnum error_codes = { :invalid_system => 20, :invalid_values => 21, :manifest_error => 22, :no_answer_file => 23, :unknown_module => 24, :defaults_error => 25} if error_codes.has_key? code return error_codes[code] else raise "Unknown code #{code}" end end |
Instance Method Details
#config ⇒ Object
48 49 50 |
# File 'lib/kafo/kafo_configure.rb', line 48 def config self.class.config end |
#execute ⇒ Object
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 |
# File 'lib/kafo/kafo_configure.rb', line 52 def execute catch :exit do 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" exit(:invalid_system) end if interactive? wizard = Wizard.new wizard.run else unless validate_all puts "Error during configuration, exiting" 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 end return self end |
#exit_code ⇒ Object
95 96 97 |
# File 'lib/kafo/kafo_configure.rb', line 95 def exit_code self.class.exit_code end |
#module(name) ⇒ Object
140 141 142 |
# File 'lib/kafo/kafo_configure.rb', line 140 def module(name) modules.detect { |m| m.name == name} end |
#modules ⇒ Object
136 137 138 |
# File 'lib/kafo/kafo_configure.rb', line 136 def modules config.modules.sort end |
#param(mod, name) ⇒ Object
144 145 146 |
# File 'lib/kafo/kafo_configure.rb', line 144 def param(mod, name) params.detect { |p| p.name == name && p.module.name == mod } end |
#params ⇒ Object
129 130 131 132 133 134 |
# File 'lib/kafo/kafo_configure.rb', line 129 def params @params ||= modules.map(&:params).flatten rescue ModuleName => e puts e exit(:unknown_module) end |