rototiller 0.0.0.b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d55671811e2416321d690faed5b873e6656bb5a
4
+ data.tar.gz: c6bd60e740eafc188f462997b429132752806a70
5
+ SHA512:
6
+ metadata.gz: 2641a1a861d9f54b1218c6b718179ff985b9f2c77a2472729d2a0ba58907279e484e6c448506b83fe8c2234720a28df78e0fe2dfdfca6a823b0f7e2c3c3437b8
7
+ data.tar.gz: 77a6855654474501fb1152b470e4e71d99c160065f0e46a0940e976f34fd1e9e01b139f7c336d677b8f933474978e210f751b5e41ab6b97e74232189895b83eb
data/Gemfile ADDED
@@ -0,0 +1,32 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # place all development, system_test, etc dependencies here
4
+
5
+ group :system_tests do
6
+ #gem 'beaker', :path => "../../beaker/"
7
+ gem 'beaker' ,'~> 2.22'
8
+ gem 'beaker-hostgenerator'
9
+ end
10
+
11
+ group :development do
12
+ gem 'rspec' ,'~> 3.1.0'
13
+ gem 'simplecov'
14
+ #Documentation dependencies
15
+ gem 'yard' ,'~> 0'
16
+ gem 'markdown' ,'~> 0'
17
+ # restrict version to enable ruby 1.9.3
18
+ gem 'mime-types' ,'~> 2.0'
19
+ end
20
+
21
+ local_gemfile = "#{__FILE__}.local"
22
+ if File.exists? local_gemfile
23
+ eval(File.read(local_gemfile), binding)
24
+ end
25
+
26
+ user_gemfile = File.join(Dir.home,'.Gemfile')
27
+ if File.exists? user_gemfile
28
+ eval(File.read(user_gemfile), binding)
29
+ end
30
+
31
+ # Specify your gem's dependencies in rototiller.gemspec
32
+ gemspec
@@ -0,0 +1,279 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rototiller (0.0.0.b)
5
+ rake
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ CFPropertyList (2.3.2)
11
+ activesupport (4.2.6)
12
+ i18n (~> 0.7)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.4.0)
18
+ aws-sdk (1.66.0)
19
+ aws-sdk-v1 (= 1.66.0)
20
+ aws-sdk-v1 (1.66.0)
21
+ json (~> 1.4)
22
+ nokogiri (>= 1.4.4)
23
+ beaker (2.37.0)
24
+ aws-sdk (~> 1.57)
25
+ beaker-answers (~> 0.0)
26
+ beaker-hiera (~> 0.0)
27
+ beaker-pe (~> 0.0)
28
+ docker-api
29
+ fission (~> 0.4)
30
+ fog (~> 1.25, < 1.35.0)
31
+ fog-google (~> 0.0.9)
32
+ google-api-client (~> 0.8)
33
+ hocon (~> 0.1)
34
+ inifile (~> 2.0)
35
+ json (~> 1.8)
36
+ mime-types (~> 2.99)
37
+ minitest (~> 5.4)
38
+ net-scp (~> 1.2)
39
+ net-ssh (~> 2.9)
40
+ open_uri_redirections (~> 0.2.1)
41
+ rbvmomi (~> 1.8)
42
+ rsync (~> 1.0.9)
43
+ stringify-hash (~> 0.0)
44
+ unf (~> 0.1)
45
+ beaker-answers (0.4.0)
46
+ require_all (~> 1.3.2)
47
+ stringify-hash (~> 0.0.0)
48
+ beaker-hiera (0.1.1)
49
+ stringify-hash (~> 0.0.0)
50
+ beaker-hostgenerator (0.4.0)
51
+ deep_merge (~> 1.0)
52
+ stringify-hash (~> 0.0.0)
53
+ beaker-pe (0.1.0)
54
+ stringify-hash (~> 0.0.0)
55
+ builder (3.2.2)
56
+ deep_merge (1.0.1)
57
+ diff-lcs (1.2.5)
58
+ docile (1.1.5)
59
+ docker-api (1.26.2)
60
+ excon (>= 0.38.0)
61
+ json
62
+ excon (0.48.0)
63
+ faraday (0.9.2)
64
+ multipart-post (>= 1.2, < 3)
65
+ fission (0.5.0)
66
+ CFPropertyList (~> 2.2)
67
+ fog (1.34.0)
68
+ fog-atmos
69
+ fog-aws (>= 0.6.0)
70
+ fog-brightbox (~> 0.4)
71
+ fog-core (~> 1.32)
72
+ fog-dynect (~> 0.0.2)
73
+ fog-ecloud (~> 0.1)
74
+ fog-google (>= 0.0.2)
75
+ fog-json
76
+ fog-local
77
+ fog-powerdns (>= 0.1.1)
78
+ fog-profitbricks
79
+ fog-radosgw (>= 0.0.2)
80
+ fog-riakcs
81
+ fog-sakuracloud (>= 0.0.4)
82
+ fog-serverlove
83
+ fog-softlayer
84
+ fog-storm_on_demand
85
+ fog-terremark
86
+ fog-vmfusion
87
+ fog-voxel
88
+ fog-xml (~> 0.1.1)
89
+ ipaddress (~> 0.5)
90
+ nokogiri (~> 1.5, >= 1.5.11)
91
+ fog-atmos (0.1.0)
92
+ fog-core
93
+ fog-xml
94
+ fog-aws (0.9.2)
95
+ fog-core (~> 1.27)
96
+ fog-json (~> 1.0)
97
+ fog-xml (~> 0.1)
98
+ ipaddress (~> 0.8)
99
+ fog-brightbox (0.10.1)
100
+ fog-core (~> 1.22)
101
+ fog-json
102
+ inflecto (~> 0.0.2)
103
+ fog-core (1.36.0)
104
+ builder
105
+ excon (~> 0.45)
106
+ formatador (~> 0.2)
107
+ fog-dynect (0.0.3)
108
+ fog-core
109
+ fog-json
110
+ fog-xml
111
+ fog-ecloud (0.3.0)
112
+ fog-core
113
+ fog-xml
114
+ fog-google (0.0.9)
115
+ fog-core
116
+ fog-json
117
+ fog-xml
118
+ fog-json (1.0.2)
119
+ fog-core (~> 1.0)
120
+ multi_json (~> 1.10)
121
+ fog-local (0.3.0)
122
+ fog-core (~> 1.27)
123
+ fog-powerdns (0.1.1)
124
+ fog-core (~> 1.27)
125
+ fog-json (~> 1.0)
126
+ fog-xml (~> 0.1)
127
+ fog-profitbricks (0.0.5)
128
+ fog-core
129
+ fog-xml
130
+ nokogiri
131
+ fog-radosgw (0.0.5)
132
+ fog-core (>= 1.21.0)
133
+ fog-json
134
+ fog-xml (>= 0.0.1)
135
+ fog-riakcs (0.1.0)
136
+ fog-core
137
+ fog-json
138
+ fog-xml
139
+ fog-sakuracloud (1.7.5)
140
+ fog-core
141
+ fog-json
142
+ fog-serverlove (0.1.2)
143
+ fog-core
144
+ fog-json
145
+ fog-softlayer (1.1.0)
146
+ fog-core
147
+ fog-json
148
+ fog-storm_on_demand (0.1.1)
149
+ fog-core
150
+ fog-json
151
+ fog-terremark (0.1.0)
152
+ fog-core
153
+ fog-xml
154
+ fog-vmfusion (0.1.0)
155
+ fission
156
+ fog-core
157
+ fog-voxel (0.1.0)
158
+ fog-core
159
+ fog-xml
160
+ fog-xml (0.1.2)
161
+ fog-core
162
+ nokogiri (~> 1.5, >= 1.5.11)
163
+ formatador (0.2.5)
164
+ google-api-client (0.9.4)
165
+ addressable (~> 2.3)
166
+ googleauth (~> 0.5)
167
+ httpclient (~> 2.7)
168
+ hurley (~> 0.1)
169
+ memoist (~> 0.11)
170
+ mime-types (>= 1.6)
171
+ representable (~> 2.3.0)
172
+ retriable (~> 2.0)
173
+ thor (~> 0.19)
174
+ googleauth (0.5.1)
175
+ faraday (~> 0.9)
176
+ jwt (~> 1.4)
177
+ logging (~> 2.0)
178
+ memoist (~> 0.12)
179
+ multi_json (~> 1.11)
180
+ os (~> 0.9)
181
+ signet (~> 0.7)
182
+ hocon (0.9.5)
183
+ httpclient (2.7.1)
184
+ hurley (0.2)
185
+ i18n (0.7.0)
186
+ inflecto (0.0.2)
187
+ inifile (2.0.2)
188
+ ipaddress (0.8.3)
189
+ json (1.8.3)
190
+ jwt (1.5.4)
191
+ kramdown (1.10.0)
192
+ little-plugger (1.1.4)
193
+ logging (2.1.0)
194
+ little-plugger (~> 1.1)
195
+ multi_json (~> 1.10)
196
+ logutils (0.6.1)
197
+ markdown (0.4.0)
198
+ kramdown (>= 0.13.7)
199
+ props (>= 0.2.0)
200
+ textutils (>= 0.2.0)
201
+ memoist (0.14.0)
202
+ mime-types (2.99.1)
203
+ mini_portile2 (2.0.0)
204
+ minitest (5.8.4)
205
+ multi_json (1.11.2)
206
+ multipart-post (2.0.0)
207
+ net-scp (1.2.1)
208
+ net-ssh (>= 2.6.5)
209
+ net-ssh (2.9.4)
210
+ nokogiri (1.6.7.2)
211
+ mini_portile2 (~> 2.0.0.rc2)
212
+ open_uri_redirections (0.2.1)
213
+ os (0.9.6)
214
+ props (1.1.2)
215
+ rake (11.1.2)
216
+ rbvmomi (1.8.2)
217
+ builder
218
+ nokogiri (>= 1.4.1)
219
+ trollop
220
+ representable (2.3.0)
221
+ uber (~> 0.0.7)
222
+ require_all (1.3.3)
223
+ retriable (2.1.0)
224
+ rspec (3.1.0)
225
+ rspec-core (~> 3.1.0)
226
+ rspec-expectations (~> 3.1.0)
227
+ rspec-mocks (~> 3.1.0)
228
+ rspec-core (3.1.7)
229
+ rspec-support (~> 3.1.0)
230
+ rspec-expectations (3.1.2)
231
+ diff-lcs (>= 1.2.0, < 2.0)
232
+ rspec-support (~> 3.1.0)
233
+ rspec-mocks (3.1.3)
234
+ rspec-support (~> 3.1.0)
235
+ rspec-support (3.1.2)
236
+ rsync (1.0.9)
237
+ rubyzip (1.2.0)
238
+ signet (0.7.2)
239
+ addressable (~> 2.3)
240
+ faraday (~> 0.9)
241
+ jwt (~> 1.5)
242
+ multi_json (~> 1.10)
243
+ simplecov (0.11.2)
244
+ docile (~> 1.1.0)
245
+ json (~> 1.8)
246
+ simplecov-html (~> 0.10.0)
247
+ simplecov-html (0.10.0)
248
+ stringify-hash (0.0.2)
249
+ textutils (1.4.0)
250
+ activesupport
251
+ logutils (>= 0.6.1)
252
+ props (>= 1.1.2)
253
+ rubyzip (>= 1.0.0)
254
+ thor (0.19.1)
255
+ thread_safe (0.3.5)
256
+ trollop (2.1.2)
257
+ tzinfo (1.2.2)
258
+ thread_safe (~> 0.1)
259
+ uber (0.0.15)
260
+ unf (0.1.4)
261
+ unf_ext
262
+ unf_ext (0.0.7.2)
263
+ yard (0.8.7.6)
264
+
265
+ PLATFORMS
266
+ ruby
267
+
268
+ DEPENDENCIES
269
+ beaker (~> 2.22)
270
+ beaker-hostgenerator
271
+ markdown (~> 0)
272
+ mime-types (~> 2.0)
273
+ rototiller!
274
+ rspec (~> 3.1.0)
275
+ simplecov
276
+ yard (~> 0)
277
+
278
+ BUNDLED WITH
279
+ 1.11.2
@@ -0,0 +1,15 @@
1
+ Copyright 2015 Puppet Labs Inc
2
+
3
+ Puppet Labs can be contacted at: info@puppetlabs.com
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,57 @@
1
+ # rototiller
2
+
3
+ A shared rake task library for use at Puppet.
4
+ Goals of Rototiller
5
+
6
+ * Provide a tool that can house shared rake task code for Puppet Labs.
7
+
8
+ * Reduce duplication in rakefiles across projects at Puppet Labs.
9
+
10
+ * Reduce effort required to write first class rake tasks.
11
+
12
+ * Reduce time and effort trying to understand requirement to run rake tasks.
13
+
14
+ * Provide a standard interface for executing tests in a given test tier regardless of framework (Not MVP)
15
+
16
+ ## Classes & Modules under development
17
+ For more detailed documentation please refer to the yard docs.
18
+
19
+ ####[EnvVar](lib/rototiller/utilities/env_var.rb)
20
+
21
+ A class that tracks the state of an ENV variable.
22
+ This class is responsible for formatting its own messaging, the value that should be used, and if a task should stop.
23
+
24
+ ####[Flag](lib/rototiller/utilities/flag.rb)
25
+
26
+ A class that tracks the desired state of command line flags used in test invocation.
27
+ The desired state of these flags is determined by the user.
28
+
29
+ ####[ParamCollection](lib/rototiller/utilities/param_collection.rb)
30
+
31
+ A class to contain EnvVar and Flag classes.
32
+ Behaves similar to an Array.
33
+
34
+ ####[RototillerTask](lib/rototiller/task/rototiller_task.rb)
35
+
36
+ A class used to build a rake task.
37
+ Similar in approach to [RSpec::Core::RakeTask](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/rake_task.rb)
38
+
39
+ ####[CLIFlags](lib/rototiller/task/flags/cli_flags.rb)
40
+
41
+ A class to contain the known CLI flags.
42
+
43
+ ## More Documentation
44
+
45
+
46
+ Rototiller is documented using yard
47
+ to view yard docs
48
+
49
+ First build a local copy of the gem
50
+
51
+ $ bundle exec rake build
52
+
53
+ Next start the yard server
54
+
55
+ $ bundle exec yard server
56
+
57
+ Finally navigate to http://0.0.0.0:8808/ to view the documentation
@@ -0,0 +1,56 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :test
5
+
6
+ desc "Run spec tests"
7
+ RSpec::Core::RakeTask.new(:test) do |t|
8
+ t.rspec_opts = ['--color']
9
+ t.pattern = 'spec/'
10
+ end
11
+
12
+ task :generate_host_config do |t, args|
13
+ if ENV["BEAKER_CONFIG"]
14
+ next
15
+ end
16
+
17
+ target = ENV["TEST_TARGET"] || 'centos7-64'
18
+ generate = "bundle exec beaker-hostgenerator"
19
+ generate += " #{target}"
20
+ generate += " > acceptance/hosts.cfg"
21
+ sh generate
22
+ sh "cat acceptance/hosts.cfg"
23
+ end
24
+
25
+ task acceptance: :generate_host_config
26
+
27
+ desc 'Run acceptance tests for Rototiller'
28
+ task :acceptance do |t, args|
29
+
30
+ config = ENV["BEAKER_CONFIG"] || 'acceptance/hosts.cfg'
31
+
32
+ preserve_hosts = ENV["BEAKER_PRESERVEHOSTS"] || 'never'
33
+ type = 'pe'
34
+ keyfile = ENV["BEAKER_KEYFILE"] || "#{ENV['HOME']}/.ssh/id_rsa-acceptance"
35
+ load_path = ENV["BEAKER_LOADPATH"] || 'acceptance/lib'
36
+ pre_suite = ENV["BEAKER_PRESUITE"] || 'acceptance/pre-suite'
37
+ post_suite = ENV["BEAKER_POSTSUITE"] || ''
38
+ test_suite = ENV["BEAKER_TESTSUITE"] || 'acceptance/tests'
39
+ opts = ENV["BEAKER_OPTS"] || ''
40
+
41
+ beaker = "bundle exec beaker "
42
+ beaker += " --xml"
43
+ beaker += " --debug"
44
+ beaker += " --root-keys"
45
+ beaker += " --repo-proxy"
46
+ beaker += " --preserve-hosts #{preserve_hosts}" if preserve_hosts != ''
47
+ beaker += " --config #{config}" if config != ''
48
+ beaker += " --type #{type}" if type != ''
49
+ beaker += " --keyfile #{keyfile}" if keyfile != ''
50
+ beaker += " --load-path #{load_path}" if load_path != ''
51
+ beaker += " --pre-suite #{pre_suite}" if pre_suite != ''
52
+ beaker += " --post-suite #{post_suite}" if post_suite != ''
53
+ beaker += " --tests #{test_suite}" if test_suite != ''
54
+ beaker += " #{opts}" if opts != ''
55
+ sh beaker
56
+ end
@@ -0,0 +1,2 @@
1
+ require 'rototiller/rake/dsl/dsl_extention'
2
+ require 'rototiller/task/rototiller_task'
@@ -0,0 +1,14 @@
1
+ require 'rototiller/task/rototiller_task'
2
+
3
+ module Rake
4
+ module DSL
5
+
6
+ def acceptance_task(*args, &block)
7
+ # Default task description
8
+ # can be overridden with 'desc' method
9
+ desc "Tests in the 'Acceptance' tier" unless ::Rake.application.last_comment
10
+ Rototiller::Task::RototillerTask.define_task :acceptance, &block
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module Rototiller
2
+ module Task
3
+ module CLIFlags
4
+ @@cli_flag_names = [:xml, :debug, :root_keys, :repo_proxy, :preserve_hosts, :config, :helper, :type, :keyfile, :options_file, :load_path, :pre_suite, :post_suite, :tests]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,95 @@
1
+ require 'rototiller/utilities/env_var'
2
+ require 'rototiller/utilities/param_collection'
3
+ require 'rototiller/utilities/env_collection'
4
+ require 'rototiller/utilities/flag_collection'
5
+ require 'rake/tasklib'
6
+
7
+ module Rototiller
8
+ module Task
9
+ class RototillerTask < ::Rake::TaskLib
10
+ attr_accessor :name
11
+ attr_accessor :command
12
+
13
+ # Whether or not to fail Rake when an error occurs (typically when
14
+ # examples fail). Defaults to `true`.
15
+ attr_accessor :fail_on_error
16
+
17
+ # A message to print to stderr when there are failures.
18
+ attr_accessor :failure_message
19
+
20
+ def initialize(*args, &task_block)
21
+ @name = args.shift
22
+ @fail_on_error = true
23
+ @command = 'echo empty RototillerTask. You should define a command, send a block, or EnvVar to track.'
24
+ # rake's in-task implied method is true when using --verbose
25
+ @verbose = verbose == true
26
+ @env_vars = EnvCollection.new
27
+ @flags = FlagCollection.new
28
+
29
+ define(args, &task_block)
30
+ end
31
+
32
+ # define_task is included to allow task to work like Rake::Task
33
+ # using .define_task or .new as appropriate
34
+ def self.define_task(*args, &task_block)
35
+ self.new(*args, &task_block)
36
+ end
37
+
38
+ #TODO add arg validation to EnvVar and CommandFlag
39
+ # add_env(EnvVar.new(), EnvVar.new(), EnvVar.new())
40
+ # add_env('FOO', 'This is how you use FOO', 'default_value')
41
+ def add_env(*args)
42
+ args.all?{ |arg| arg.is_a?(EnvVar)} ? @env_vars.push(*args) : @env_vars.push(EnvVar.new(*args))
43
+ end
44
+
45
+ #TODO add arg validation to CommandFlag
46
+ # add_flag(CommandFlag.new(), CommandFlag.new(), CommandFlag.new())
47
+ # add_flag('--foo', 'This is how you use --foo', 'default_value')
48
+ def add_flag(*args)
49
+ args.all?{ |arg| arg.is_a?(CommandFlag)} ? @flags.push(*flags) : @flags.push(CommandFlag.new(*args))
50
+ end
51
+
52
+ private
53
+
54
+ # @private
55
+ def run_task
56
+ puts @flags.format_messages
57
+ puts @env_vars.format_messages
58
+ exit if @env_vars.stop?
59
+
60
+ command_str = @command << @flags.to_s
61
+ puts command_str if @verbose
62
+
63
+ return if system(command_str)
64
+ puts failure_message if failure_message
65
+
66
+ return unless fail_on_error
67
+ $stderr.puts "#{command_str} failed" if @verbose
68
+ exit $?.exitstatus
69
+ end
70
+
71
+ # @private
72
+ # register the new block w/ run_task call in a rake task
73
+ # any block passed is run prior to our command
74
+ # TODO: probably need pre/post-command block functionality
75
+ def define(args, &task_block)
76
+ # Default task description
77
+ # can be overridden with standard 'desc' DSL method
78
+ desc "RototillerTask: A Task with optional environment variable and command flag tracking" unless ::Rake.application.last_comment
79
+
80
+ task(@name, *args) do |_, task_args|
81
+ RakeFileUtils.__send__(:verbose, @verbose) do
82
+ task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
83
+ run_task
84
+ end
85
+ end
86
+ end
87
+
88
+ # @private
89
+ # for unit testing, we need a shortcut around rake's CLI --verbose
90
+ def set_verbose(verbosity=true)
91
+ @verbose = verbosity
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,32 @@
1
+ module ColorText
2
+
3
+ # Colors a string of text
4
+ # @param text [String] the text to color
5
+ # @param color [Integer] ASCII-code 30-37 http://ascii-table.com/ansi-escape-sequences.php
6
+ # @return [String] formatted text with color
7
+ def colorize(text, color)
8
+ "\e[#{color}m#{text}\e[0m"
9
+ end
10
+
11
+ # Adds yellow color to a string of text
12
+ # @param text [String] The text to color
13
+ # @return [String] Text formatted in yellow color
14
+ def yellow_text(text)
15
+ colorize(text, 33)
16
+ end
17
+
18
+ # Adds green color to a string of text
19
+ # @param text [String] The text to color
20
+ # @return [String] Text formatted in green color
21
+ def green_text(text)
22
+ colorize(text, 32)
23
+ end
24
+
25
+ # Adds red color to a string of text
26
+ # @param text [String] The text to color
27
+ # @return [String] Text formatted in red color
28
+ def red_text(text)
29
+ colorize(text, 31)
30
+ end
31
+
32
+ end
@@ -0,0 +1,35 @@
1
+ require 'rototiller/utilities/color_text'
2
+
3
+ class CommandFlag
4
+
5
+ include ColorText
6
+
7
+ # @return [String] the flag to be set on a CLI '-v' or '--verbose'
8
+ attr_reader :flag
9
+
10
+ # @return [true, false, nil, String] the value if any of the flag
11
+ attr_reader :value
12
+
13
+ # Creates a new instance of CommandFlag, holds information about desired state of a CLI flag
14
+ # @param flag [String] the flag to be set on a CLI '-v' or '--verbose'
15
+ # @param message [String] the message describing the Flag
16
+ # @param value [String] the value to use as the value if one is required
17
+ def initialize(flag, value=nil, message)
18
+ @flag = flag
19
+ @message = message
20
+ @value = value
21
+ end
22
+
23
+ # The formatted message to be displayed to the user
24
+ # @return [String] the CommandFlag's message, formatted with color
25
+ def message
26
+ green_text(@message) << "\n" << describe_flag_state
27
+ end
28
+
29
+ private
30
+ def describe_flag_state
31
+ only_flag = "The CLI flag #{@flag} will be used, no value was provided."
32
+ flag_with_value = "The CLI flag #{@flag} will be used with value #{@value}."
33
+ green_text(@value.nil? ? only_flag : flag_with_value)
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'rototiller/utilities/param_collection'
2
+
3
+ class EnvCollection < ParamCollection
4
+
5
+ def push(*args)
6
+ check_classes(EnvVar, *args)
7
+ super
8
+ end
9
+
10
+ # Do any of the contents of this ParamCollection require the task to stop
11
+ # @return [true, nil] should the values of this ParamCollection stop the task
12
+ def stop?
13
+ @collection.any?{ |param| param.stop }
14
+ end
15
+ end
@@ -0,0 +1,62 @@
1
+ require 'rototiller/utilities/color_text'
2
+
3
+ class EnvVar
4
+
5
+ include ColorText
6
+
7
+ attr_accessor :var, :message, :default
8
+
9
+ # @return [Symbol] the debug level of the message, ':warning', ':error', ':info'
10
+ attr_reader :message_level
11
+
12
+ # @return [true, nil] if the state of the EnvVar requires the task to stop
13
+ attr_reader :stop
14
+
15
+ # Creates a new instance of EnvVar, holds information about the ENV in the environment
16
+ # @param var [String] the ENV in the environment, 'HOME'
17
+ # @param message [String] the message describing the ENV
18
+ # @param default [String] the value to use as the default if the ENV is not present
19
+ def initialize(var, default=false, message)
20
+ @var = var
21
+ @message = message
22
+ @default = default
23
+ set_message_level
24
+ end
25
+
26
+ # The value of the ENV determined by the EnvVar class
27
+ # @return [String] the value determined by the EnvVar class
28
+ def value
29
+ ENV[@var] || @default
30
+ end
31
+
32
+ # The formatted message to be displayed to the user
33
+ # @return [String] the EnvVar's message, formatted for color and meaningful to the state of the EnvVAr
34
+ def message
35
+ if message_level == :error
36
+ red_text("The ENV #{@var} is required, #{@message}")
37
+ elsif message_level == :info
38
+ green_text("The ENV #{@var} was found in the environment with the value #{value}")
39
+ elsif message_level == :warning
40
+ yellow_text("WARNING: the ENV #{@var} is not set, proceeding with default value: #{@default}")
41
+ end
42
+ end
43
+
44
+ private
45
+ def check
46
+ ENV.key?(@var)
47
+ end
48
+
49
+ def set_message_level
50
+ if !@default && !check
51
+ # ENV is not Present and it has no default value
52
+ @message_level = :error
53
+ @stop = true
54
+ elsif !@default && check || @default && check
55
+ # ENV is present and it has no default value
56
+ @message_level = :info
57
+ elsif @default && !check
58
+ # ENV is not present and it has default value
59
+ @message_level = :warning
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,26 @@
1
+ require 'rototiller/utilities/param_collection'
2
+
3
+ class FlagCollection < ParamCollection
4
+
5
+ def push(*args)
6
+ check_classes(CommandFlag, *args)
7
+ super
8
+ end
9
+
10
+ # Joins contents into a String, works with no value flags and flags with value
11
+ # @return [String] flags formatted into a single string
12
+ def to_s
13
+
14
+ flag_str = String.new
15
+
16
+ @collection.each do |flag|
17
+ if flag.value.nil?
18
+ flag_str << ' ' << flag.flag
19
+ else
20
+ flag_str << ' ' << flag.flag << ' ' << flag.value
21
+ end
22
+ end
23
+
24
+ flag_str
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ require 'rototiller/utilities/command_flag'
2
+ require 'rototiller/utilities/env_var'
3
+ require 'forwardable'
4
+
5
+ class ParamCollection
6
+
7
+ # This may be useful if we use individual ParamCollection objects for EnvVars and Flags
8
+ extend Forwardable
9
+
10
+ def_delegators :@collection, :clear, :delete_if, :include?, :include, :inspect, :push
11
+
12
+ # collect a given task's params
13
+ def initialize
14
+ @collection = []
15
+ end
16
+
17
+ # format the messages inside this ParamCollection
18
+ # @param [Hash] filters any method from EnvVar can be used as a key
19
+ # @option filters [String, false, true] :stop the value of the return from .stop on EnvVar
20
+ # @option filters [String, false, true] :message_level the value of the return from .message_level on EnvVar
21
+ # @option filters [String, false, true] :default the value of the return from .default on EnvVar
22
+ # @option filters [String, false, true] :message the value of the return from .message on EnvVar
23
+ # @option filters [String, false, true] :var the value of the return from .var on EnvVar
24
+ # @return [String] messages from the contents of this ParamCollection, formatted with new lines and color
25
+ # @example Get the messages where :stop is true & :message_level is :warning
26
+ 'format_message({:stop => true, :message_level => :warning})'
27
+ def format_messages(filters=nil)
28
+
29
+ formatted_message = String.new
30
+ build_message = lambda { |param| formatted_message << param.message << "\n"}
31
+ filters ? filter_contents(filters).each(&build_message) : @collection.each(&build_message)
32
+ formatted_message
33
+ end
34
+
35
+ def filter_contents(filters={})
36
+
37
+ filtered = []
38
+
39
+ @collection.each do |param|
40
+
41
+ filtered.push(param) if filters.all? do |method, value|
42
+
43
+ if param.respond_to?(method)
44
+ if param.send(method).nil?
45
+ value.nil?
46
+ else
47
+ param.send(method).to_s =~ /#{value.to_s}/
48
+ end
49
+ end
50
+ end
51
+ end
52
+ filtered
53
+ end
54
+
55
+ def check_classes(allowed_klass, *args)
56
+
57
+ args.each do |arg|
58
+
59
+ unless arg.is_a?(allowed_klass)
60
+ argument_error = "Argument was of class #{arg.class}, Can only be of class #{allowed_klass}"
61
+ raise(ArgumentError, argument_error)
62
+ end
63
+ end
64
+ end
65
+
66
+ private :filter_contents, :check_classes
67
+ end
@@ -0,0 +1,5 @@
1
+ module Rototiller
2
+ module Version
3
+ STRING = '0.0.0.b'
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ if ENV["COVERAGE"]
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+ add_filter '.bundle/gems'
6
+ end
7
+ end
8
+
9
+ require 'rspec'
10
+ require 'rototiller'
11
+
12
+ def random_string
13
+ (0...10).map { ('a'..'z').to_a[rand(26)] }.join
14
+ end
15
+
16
+ def set_random_env
17
+ name = unique_env
18
+ ENV[name] = random_string
19
+ return name
20
+ end
21
+
22
+ def unique_env
23
+ env = random_string
24
+ env = random_string until !ENV[env]
25
+ return env
26
+ end
27
+
28
+ def with_captured_stdout
29
+ begin
30
+ old_stdout = $stdout
31
+ $stdout = StringIO.new('','w')
32
+ yield
33
+ $stdout.string
34
+ ensure
35
+ $stdout = old_stdout
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |config|
40
+ config.include Rake::DSL
41
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rototiller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.b
5
+ platform: ruby
6
+ authors:
7
+ - Puppetlabs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Puppetlabs tool for building rake tasks
28
+ email:
29
+ - qa@puppetlabs.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE.md
37
+ - README.md
38
+ - Rakefile
39
+ - lib/rototiller.rb
40
+ - lib/rototiller/rake/dsl/dsl_extention.rb
41
+ - lib/rototiller/task/flags/cli_flags.rb
42
+ - lib/rototiller/task/rototiller_task.rb
43
+ - lib/rototiller/utilities/color_text.rb
44
+ - lib/rototiller/utilities/command_flag.rb
45
+ - lib/rototiller/utilities/env_collection.rb
46
+ - lib/rototiller/utilities/env_var.rb
47
+ - lib/rototiller/utilities/flag_collection.rb
48
+ - lib/rototiller/utilities/param_collection.rb
49
+ - lib/rototiller/version.rb
50
+ - spec/spec_helper.rb
51
+ homepage: https://github.com/puppetlabs/rototiller
52
+ licenses:
53
+ - Apache-2.0
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>'
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.1
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.6.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Puppetlabs rake tool
75
+ test_files: []
76
+ has_rdoc: