kafo 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kafo might be problematic. Click here for more details.

@@ -1,60 +1,62 @@
1
1
  # encoding: UTF-8
2
- class Validator
3
-
4
- def initialize(params)
5
- files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/validate_*.rb'
6
- Dir.glob(files).each do |file|
7
- require file
2
+ module Kafo
3
+ class Validator
4
+
5
+ def initialize(params)
6
+ files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/validate_*.rb'
7
+ Dir.glob(files).each do |file|
8
+ require file
9
+ end
10
+
11
+ @params = params
12
+ @logger = KafoConfigure.logger
13
+
14
+ @cache ||= Hash.new do |hash, key|
15
+ @logger.debug "Looked for #{key}"
16
+ param = @params.select { |p| p.name == key.to_s }.first
17
+ hash[key] = param.nil? ? nil : param.value
18
+ end
8
19
  end
9
20
 
10
- @params = params
11
- @logger = KafoConfigure.logger
12
-
13
- @cache ||= Hash.new do |hash, key|
14
- @logger.debug "Looked for #{key}"
15
- param = @params.select { |p| p.name == key.to_s }.first
16
- hash[key] = param.nil? ? nil : param.value
21
+ def lookupvar(name, options = {})
22
+ @cache[name]
17
23
  end
18
- end
19
-
20
- def lookupvar(name, options = {})
21
- @cache[name]
22
- end
23
24
 
24
- # for puppet >= 3
25
- def include?(value)
26
- true
27
- end
25
+ # for puppet >= 3
26
+ def include?(value)
27
+ true
28
+ end
28
29
 
29
- # for puppet >= 3
30
- def [](value, *args)
31
- lookupvar(value)
32
- end
30
+ # for puppet >= 3
31
+ def [](value, *args)
32
+ lookupvar(value)
33
+ end
33
34
 
34
- def method_missing(method, *args, &block)
35
- method.to_s =~ /^function_(.*)$/
36
- super unless $1
37
- super unless Puppet::Parser::Functions.function($1)
38
- # In odd circumstances, this might not end up defined by the previous
39
- # method, so we might as well be certain.
40
- if engine.respond_to? method
41
- @logger.debug "calling #{method.inspect} with #{args.inspect}"
42
- engine.send(method, *args)
43
- else
44
- raise Puppet::DevError, "Function #{$1} not defined despite being loaded!"
35
+ def method_missing(method, *args, &block)
36
+ method.to_s =~ /^function_(.*)$/
37
+ super unless $1
38
+ super unless Puppet::Parser::Functions.function($1)
39
+ # In odd circumstances, this might not end up defined by the previous
40
+ # method, so we might as well be certain.
41
+ if engine.respond_to? method
42
+ @logger.debug "calling #{method.inspect} with #{args.inspect}"
43
+ engine.send(method, *args)
44
+ else
45
+ raise Puppet::DevError, "Function #{$1} not defined despite being loaded!"
46
+ end
47
+ rescue Puppet::ParseError => e
48
+ @logger.error e.message
49
+ return false
45
50
  end
46
- rescue Puppet::ParseError => e
47
- @logger.error e.message
48
- return false
49
- end
50
51
 
51
- private
52
+ private
52
53
 
53
- def engine
54
- @engine ||= begin
55
- klass = Class.new
56
- klass.send :include, Puppet::Parser::Functions.environment_module
57
- klass.new
54
+ def engine
55
+ @engine ||= begin
56
+ klass = Class.new
57
+ klass.send :include, Puppet::Parser::Functions.environment_module
58
+ klass.new
59
+ end
58
60
  end
59
61
  end
60
62
  end
data/lib/kafo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
data/lib/kafo/wizard.rb CHANGED
@@ -2,130 +2,170 @@
2
2
  require 'highline/import'
3
3
  require 'yaml'
4
4
 
5
- class Wizard
6
- def initialize
7
- setup_terminal
8
- setup_colors
9
- @name = 'Kafo'
10
- @config = KafoConfigure.config
11
- end
5
+ module Kafo
6
+ class Wizard
7
+ def initialize(kafo)
8
+ @kafo = kafo
9
+ @config = kafo.config
10
+ @name = @config.app[:name] || 'Kafo'
11
+ setup_terminal
12
+ setup_colors
13
+ end
12
14
 
13
- def run
14
- message = "Welcome to the #{@name} installer!"
15
- say("<%= color('#{message}', :headline) %>")
16
- say("<%= color('#{'-' * message.size}', :horizontal_line) %>")
17
- say(<<END)
15
+ def run
16
+ message = "Welcome to the #{@name} installer!"
17
+ say("<%= color('#{message}', :headline) %>")
18
+ say("<%= color('#{'-' * message.size}', :horizontal_line) %>")
19
+ say(<<END)
18
20
 
19
21
  This wizard will gather all required information. You can change any parameter to your needs.
20
22
 
21
23
  END
22
24
 
23
- exit 0 unless agree("\n<%= color('Ready to start?', :question) %> (y/n)", false)
25
+ exit 0 unless agree("\n<%= color('Ready to start?', :question) %> (y/n)", false)
24
26
 
25
- main_menu
26
- end
27
+ main_menu
28
+ rescue Interrupt
29
+ puts "Got interrupt, exiting"
30
+ exit(0)
31
+ end
27
32
 
28
- private
29
-
30
- def main_menu
31
- finished = false
32
- until finished
33
- say("\n<%= color('Main Config Menu', :headline) %>")
34
- choose do |menu|
35
- menu.prompt = 'Choose an option from the menu... '
36
- @config.modules.each do |mod|
37
- menu.choice "[#{mod.enabled? ? '✓' : '✗'}] Configure #{mod.name}" do
38
- configure_module(mod)
33
+ private
34
+
35
+ def main_menu
36
+ finished = false
37
+ until finished
38
+ say("\n<%= color('Main Config Menu', :headline) %>")
39
+ choose do |menu|
40
+ menu.prompt = 'Choose an option from the menu... '
41
+ @config.modules.each do |mod|
42
+ menu.choice "[#{mod.enabled? ? '✓' : '✗'}] Configure #{mod.name}" do
43
+ configure_module(mod)
44
+ end
45
+ end
46
+ menu.choice "Display current config" do
47
+ display_hash
48
+ end
49
+ menu.choice "<%= color('Save and run', :run) %>" do
50
+ KafoConfigure.config
51
+ finished = true
52
+ end
53
+ menu.choice "<%= color('Cancel run without Saving', :cancel) %>" do
54
+ say("Bye!"); exit 0
39
55
  end
40
- end
41
- menu.choice "Display current config" do
42
- display_hash
43
- end
44
- menu.choice "<%= color('Save and run', :run) %>" do
45
- KafoConfigure.config
46
- finished = true
47
- end
48
- menu.choice "<%= color('Cancel run without Saving', :cancel) %>" do
49
- say("Bye!"); exit 0
50
56
  end
51
57
  end
52
58
  end
53
- end
54
59
 
55
- def display_hash
56
- data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
57
- say "<%= color('#{YAML.dump data}', :info) %>"
58
- end
60
+ def display_hash
61
+ data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
62
+ say "<%= color('#{YAML.dump data}', :info) %>"
63
+ end
59
64
 
60
- def configure_module(mod)
61
- go_back = false
62
- until go_back
63
- say("\n<%= color('Module #{mod.name} configuration', :headline) %>")
64
- choose do |menu|
65
- menu.prompt = 'Choose an option from the menu... '
66
- menu.choice("Enable/disable #{mod.name} module, current value: <%= color('#{mod.enabled?}', :info) %>") { turn_module(mod) }
67
- if mod.enabled?
68
- mod.params.each do |param|
69
- menu.choice "Set <%= color('#{param.name}', :important) %>, current value: <%= color('#{param.value}', :info) %>" do
70
- configure(param)
65
+ def configure_module(mod)
66
+ go_back = false
67
+ until go_back
68
+ say("\n<%= color('Module #{mod.name} configuration', :headline) %>")
69
+ choose do |menu|
70
+ menu.prompt = 'Choose an option from the menu... '
71
+ menu.choice("Enable/disable #{mod.name} module, current value: <%= color('#{mod.enabled?}', :info) %>") { turn_module(mod) }
72
+ if mod.enabled?
73
+ render_params(mod.primary_parameter_group.params, menu)
74
+
75
+ others = mod.primary_parameter_group.children + mod.other_parameter_groups
76
+ others.each do |group|
77
+ menu.choice("Configure #{group.formatted_name}") { configure_group(group) }
71
78
  end
72
79
  end
80
+ menu.choice("Back to main menu") { go_back = true }
73
81
  end
74
- menu.choice("Back to main menu") { go_back = true }
75
82
  end
76
83
  end
77
- end
78
84
 
79
- def configure(param)
80
- say "\n<%= color('Parameter #{param.name} (of module #{param.module.name})', :headline) %>"
81
- say "<%= color(\"#{param.doc.join("\n").gsub('"','\"')}\", :important) %>"
82
- value = param.multivalued? ? configure_multi(param) : configure_single(param)
83
- value_was = param.value
84
- param.value = value unless value.empty?
85
-
86
- until param.valid?
87
- param.value = value_was
88
- say "\n<%= color('Invalid value for #{param.name}', :important) %>"
89
- value = param.multivalued? ? configure_multi(param) : configure_single(param)
85
+ def configure_group(group)
86
+ go_back = false
87
+ until go_back
88
+ say "\n<%= color('Group #{group.formatted_name} (of module #{group.module.name})', :headline) %>"
89
+ choose do |menu|
90
+
91
+ render_params(group.params, menu)
92
+
93
+ group.children.each do |subgroup|
94
+ menu.choice("Configure #{subgroup.formatted_name}") { configure_group(subgroup) }
95
+ end
96
+
97
+ menu.choice("Back to parent menu") { go_back = true }
98
+ end
99
+ end
100
+ end
101
+
102
+ def render_params(params, menu)
103
+ params.each do |param|
104
+ if param.visible?(@kafo.params)
105
+ menu.choice "Set <%= color('#{param.name}', :important) %>, current value: <%= color('#{param.value}', :info) %>" do
106
+ configure(param)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ def configure(param)
113
+ say "\n<%= color('Parameter #{param.name} (of module #{param.module.name})', :headline) %>"
114
+ say "<%= color(\"#{param.doc.join("\n").gsub('"', '\"')}\", :important) %>"
115
+ value = param.multivalued? ? configure_multi(param) : configure_single(param)
116
+ value_was = param.value
90
117
  param.value = value unless value.empty?
118
+
119
+ until param.valid?
120
+ param.value = value_was
121
+ say "\n<%= color('Invalid value for #{param.name}', :important) %>"
122
+ value = param.multivalued? ? configure_multi(param) : configure_single(param)
123
+ param.value = value unless value.empty?
124
+ end
91
125
  end
92
- end
93
126
 
94
- def configure_single(param)
95
- say "\ncurrent value: <%= color('#{param.value}', :info) %>"
96
- ask("new value:")
97
- end
127
+ def configure_single(param)
128
+ say "\ncurrent value: <%= color('#{param.value}', :info) %>"
129
+ ask("new value:")
130
+ end
131
+
132
+ def configure_multi(param)
133
+ say "<%= color('every line is a separate value, blank line to quit', :info) %>"
134
+ say "\ncurrent value: <%= color('#{param.value}', :info) %>"
135
+ ask("new value:") do |q|
136
+ q.gather = ""
137
+ end
98
138
 
99
- def configure_multi(param)
100
- say "<%= color('every line is a separate value, blank line to quit', :info) %>"
101
- say "\ncurrent value: <%= color('#{param.value}', :info) %>"
102
- ask("new value:") do |q|
103
- q.gather = ""
104
139
  end
105
140
 
106
- end
141
+ def turn_module(mod)
142
+ agree("Enable #{mod.name} module? (y/n) ") ? mod.enable : mod.disable
143
+ end
107
144
 
108
- def turn_module(mod)
109
- agree("Enable #{mod.name} module? (y/n) ") ? mod.enable : mod.disable
110
- end
145
+ def setup_terminal
146
+ $terminal = HighLine.new
147
+ data = HighLine::SystemExtensions.terminal_size
148
+ $terminal.wrap_at = data.first > 80 ? 80 : data.first
149
+ $terminal.page_at = data.last
150
+ end
111
151
 
112
- def setup_terminal
113
- $terminal = HighLine.new
114
- data = HighLine::SystemExtensions.terminal_size
115
- $terminal.wrap_at = data.first > 80 ? 80 : data.first
116
- $terminal.page_at = data.last
117
- end
152
+ # setup colour scheme for prompts
153
+ def setup_colors
154
+ colors = HighLine::ColorScheme.new do |cs|
155
+ cs[:headline] = [:bold, :yellow, :on_black]
156
+ cs[:horizontal_line] = [:bold, :white, :on_black]
157
+ cs[:important] = [:bold, :white, :on_black]
158
+ cs[:question] = [:bold, :green, :on_black]
159
+ cs[:info] = [:bold, :cyan, :on_black]
160
+ cs[:cancel] = [:bold, :red, :on_black]
161
+ cs[:run] = [:bold, :green, :on_black]
162
+ end
163
+
164
+ nocolors = HighLine::ColorScheme.new do |cs|
165
+ colors.keys.each { |k| cs[k.to_sym] = [] }
166
+ end
118
167
 
119
- # setup colour scheme for prompts
120
- def setup_colors
121
- HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
122
- cs[:headline] = [:bold, :yellow, :on_black]
123
- cs[:horizontal_line] = [:bold, :white, :on_black]
124
- cs[:important] = [:bold, :white, :on_black]
125
- cs[:question] = [:bold, :green, :on_black]
126
- cs[:info] = [:bold, :cyan, :on_black]
127
- cs[:cancel] = [:bold, :red, :on_black]
128
- cs[:run] = [:bold, :green, :on_black]
168
+ HighLine.color_scheme = @config.app[:colors] ? colors : nocolors
129
169
  end
130
170
  end
131
171
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 4.7.5
47
+ version: 5.0.8
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 4.7.5
54
+ version: 5.0.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: puppet
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - '>='
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: 0.6.2
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - '>='
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 0.6.2
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: highline
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -151,13 +165,18 @@ files:
151
165
  - bin/kafofy
152
166
  - config/kafo.yaml.example
153
167
  - config/config_header.txt
168
+ - lib/kafo/condition.rb
154
169
  - lib/kafo/puppet_module.rb
155
170
  - lib/kafo/puppet_module_parser.rb
171
+ - lib/kafo/doc_parser.rb
156
172
  - lib/kafo/password_manager.rb
157
173
  - lib/kafo/configuration.rb
158
174
  - lib/kafo/validator.rb
159
175
  - lib/kafo/exceptions.rb
160
176
  - lib/kafo/system_checker.rb
177
+ - lib/kafo/help_builders/base.rb
178
+ - lib/kafo/help_builders/advanced.rb
179
+ - lib/kafo/help_builders/basic.rb
161
180
  - lib/kafo/progress_bar.rb
162
181
  - lib/kafo/puppet_command.rb
163
182
  - lib/kafo/wizard.rb
@@ -166,9 +185,12 @@ files:
166
185
  - lib/kafo/params/boolean.rb
167
186
  - lib/kafo/params/array.rb
168
187
  - lib/kafo/params/integer.rb
188
+ - lib/kafo/help_builder.rb
169
189
  - lib/kafo/kafo_configure.rb
190
+ - lib/kafo/hooking.rb
170
191
  - lib/kafo/string_helper.rb
171
192
  - lib/kafo/logger.rb
193
+ - lib/kafo/param_group.rb
172
194
  - lib/kafo/progress_bars/colored.rb
173
195
  - lib/kafo/progress_bars/black_white.rb
174
196
  - lib/kafo/param.rb