Class: Kafo::KafoConfigure

Inherits:
Clamp::Command
  • Object
show all
Includes:
StringHelper
Defined in:
lib/kafo/kafo_configure.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StringHelper

#dashize, #parametrize, #underscore, #with_prefix

Constructor Details

#initialize(*args) ⇒ KafoConfigure

Returns a new instance of KafoConfigure.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kafo/kafo_configure.rb', line 31

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.expand_path(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.expand_path(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
  self.class.hooking.kafo     = self

  super

  set_app_options
  # 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
  Logger.setup

  set_parameters # here the params gets parsed and we need app config populated
  set_options
end

Class Attribute Details

.app_optionsObject

Returns the value of attribute app_options.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def app_options
  @app_options
end

.configObject

Returns the value of attribute config.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def config
  @config
end

.config_fileObject

Returns the value of attribute config_file.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def config_file
  @config_file
end

.gem_rootObject

Returns the value of attribute gem_root.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def gem_root
  @gem_root
end

.hookingObject



26
27
28
# File 'lib/kafo/kafo_configure.rb', line 26

def hooking
  @hooking ||= Hooking.new
end

.kafo_modules_dirObject

Returns the value of attribute kafo_modules_dir.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def kafo_modules_dir
  @kafo_modules_dir
end

.loggerObject

Returns the value of attribute logger.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def logger
  @logger
end

.modules_dirObject

Returns the value of attribute modules_dir.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def modules_dir
  @modules_dir
end

.root_dirObject

Returns the value of attribute root_dir.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def root_dir
  @root_dir
end

.temp_config_fileObject

Returns the value of attribute temp_config_file.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def temp_config_file
  @temp_config_file
end

.verboseObject

Returns the value of attribute verbose.



22
23
24
# File 'lib/kafo/kafo_configure.rb', line 22

def verbose
  @verbose
end

Class Method Details

.app_option(*args, &block) ⇒ Object



142
143
144
145
146
# File 'lib/kafo/kafo_configure.rb', line 142

def self.app_option(*args, &block)
  self.app_options ||= []
  self.app_options.push self.option(*args, &block)
  self.app_options.last
end

.exit(code) ⇒ Object



107
108
109
110
# File 'lib/kafo/kafo_configure.rb', line 107

def self.exit(code)
  @exit_code = translate_exit_code(code)
  throw :exit
end

.exit_codeObject



112
113
114
# File 'lib/kafo/kafo_configure.rb', line 112

def self.exit_code
  @exit_code ||= 0
end

.help(*args) ⇒ Object



135
136
137
138
139
140
# File 'lib/kafo/kafo_configure.rb', line 135

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

.runObject



96
97
98
99
100
101
# File 'lib/kafo/kafo_configure.rb', line 96

def self.run
  catch :exit do
    return super
  end
  Kernel.exit(self.exit_code) # fail in initialize
end

.translate_exit_code(code) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/kafo/kafo_configure.rb', line 116

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

#configObject



56
57
58
# File 'lib/kafo/kafo_configure.rb', line 56

def config
  self.class.config
end

#executeObject



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
# File 'lib/kafo/kafo_configure.rb', line 60

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(self)
      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_codeObject



103
104
105
# File 'lib/kafo/kafo_configure.rb', line 103

def exit_code
  self.class.exit_code
end

#helpObject



131
132
133
# File 'lib/kafo/kafo_configure.rb', line 131

def help
  self.class.help(invocation_path, self)
end

#module(name) ⇒ Object



159
160
161
# File 'lib/kafo/kafo_configure.rb', line 159

def module(name)
  modules.detect { |m| m.name == name }
end

#modulesObject



155
156
157
# File 'lib/kafo/kafo_configure.rb', line 155

def modules
  config.modules.sort
end

#param(mod, name) ⇒ Object



163
164
165
# File 'lib/kafo/kafo_configure.rb', line 163

def param(mod, name)
  params.detect { |p| p.name == name && p.module.name == mod }
end

#paramsObject



148
149
150
151
152
153
# File 'lib/kafo/kafo_configure.rb', line 148

def params
  @params ||= modules.map(&:params).flatten
rescue ModuleName => e
  puts e
  exit(:unknown_module)
end