boxen 3.0.0.beta1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/README.md +1 -1
  4. data/boxen.gemspec +13 -13
  5. data/lib/boxen/check.rb +39 -8
  6. data/lib/boxen/cli.rb +45 -19
  7. data/lib/boxen/config.rb +61 -43
  8. data/lib/boxen/flags.rb +282 -0
  9. data/lib/boxen/hook.rb +8 -15
  10. data/lib/boxen/hook/github_issue.rb +120 -0
  11. data/lib/boxen/hook/web.rb +56 -0
  12. data/lib/boxen/keychain.rb +1 -1
  13. data/lib/boxen/postflight/env.rb +1 -1
  14. data/lib/boxen/preflight.rb +7 -4
  15. data/lib/boxen/preflight/creds.rb +47 -8
  16. data/lib/boxen/preflight/identity.rb +0 -2
  17. data/lib/boxen/preflight/os.rb +6 -2
  18. data/lib/boxen/puppeteer.rb +121 -0
  19. data/lib/boxen/runner.rb +149 -0
  20. data/script/bootstrap +1 -1
  21. data/script/tests +0 -1
  22. data/test/boxen/test.rb +1 -1
  23. data/test/boxen_check_test.rb +55 -0
  24. data/test/boxen_cli_test.rb +31 -8
  25. data/test/boxen_config_test.rb +31 -1
  26. data/test/boxen_directories_test.rb +4 -4
  27. data/test/boxen_flags_test.rb +217 -0
  28. data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb} +82 -72
  29. data/test/{postflight/boxen_postflight_web_hook_test.rb → boxen_hook_web_test.rb} +11 -12
  30. data/test/{postflight/boxen_postflight_active_test.rb → boxen_postflight_active_test.rb} +3 -3
  31. data/test/{postflight/boxen_postflight_env_test.rb → boxen_postflight_env_test.rb} +0 -0
  32. data/test/boxen_preflight_creds_test.rb +177 -0
  33. data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb} +1 -1
  34. data/test/{preflight/boxen_preflight_rvm_test.rb → boxen_preflight_rvm_test.rb} +1 -1
  35. data/test/boxen_puppeteer_test.rb +101 -0
  36. data/test/boxen_runner_test.rb +171 -0
  37. metadata +172 -251
  38. data/lib/boxen/command.rb +0 -142
  39. data/lib/boxen/command/help.rb +0 -40
  40. data/lib/boxen/command/preflight.rb +0 -38
  41. data/lib/boxen/command/project.rb +0 -49
  42. data/lib/boxen/command/project/install.rb +0 -33
  43. data/lib/boxen/command/run.rb +0 -199
  44. data/lib/boxen/command/service.rb +0 -61
  45. data/lib/boxen/command/service/disable.rb +0 -15
  46. data/lib/boxen/command/service/enable.rb +0 -15
  47. data/lib/boxen/command/service/restart.rb +0 -24
  48. data/lib/boxen/command/version.rb +0 -29
  49. data/lib/boxen/command_status.rb +0 -15
  50. data/lib/boxen/postflight/github_issue.rb +0 -124
  51. data/lib/boxen/postflight/hooks.rb +0 -16
  52. data/lib/boxen/postflight/web_hook.rb +0 -63
  53. data/lib/boxen/preflight/facts.rb +0 -36
  54. data/lib/boxen/preflight/homebrew.rb +0 -13
  55. data/lib/boxen/preflight/offline.rb +0 -33
  56. data/lib/boxen/preflight/update.rb +0 -109
  57. data/lib/boxen/util/logging.rb +0 -59
  58. data/lib/boxen/version.rb +0 -3
  59. data/lib/system_timer.rb +0 -13
  60. data/test/boxen_command_test.rb +0 -93
  61. data/test/boxen_hook_test.rb +0 -25
  62. data/test/command/help_test.rb +0 -49
  63. data/test/command/project/install_test.rb +0 -34
  64. data/test/command/project_test.rb +0 -32
  65. data/test/command/run_test.rb +0 -21
  66. data/test/command/service/disable_test.rb +0 -49
  67. data/test/command/service/enable_test.rb +0 -49
  68. data/test/command/service/restart_test.rb +0 -53
  69. data/test/command/service_test.rb +0 -55
  70. data/test/command/version_test.rb +0 -15
  71. data/test/preflight/boxen_preflight_creds_test.rb +0 -82
  72. data/test/preflight/boxen_preflight_homebrew_test.rb +0 -10
  73. data/test/system_timer.rb +0 -10
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2446bd003647a42616bee6f20530f55b3b56b678
4
+ data.tar.gz: a5bc7868ad7ba25d216e9cdc0feaa10166b0e35f
5
+ SHA512:
6
+ metadata.gz: c8ace9ed36907e0cf2ac8679a33d4fe7f253c927ea5460ef05ce9a34e0d64c5590e081e0a1917717f971ffca97fd809f1fbf89d9df2863ed5e08938a922bdba9
7
+ data.tar.gz: 3ef57a22a4192307c3c67ddee992d693fe37f3830c5a1aa398282adc66af7733306f4471bc270514db924bb8b8e03a66567e54f9de06e35948a7a16f8ca9b96d
@@ -3,5 +3,4 @@ before_install: gem update --system 2.1.11
3
3
  script: "./script/tests"
4
4
  gemfile: "this/does/not/exist"
5
5
  rvm:
6
- - "1.8.7"
7
6
  - "2.0.0"
data/README.md CHANGED
@@ -42,7 +42,7 @@ and we can't just modify the sudoers file due to a chicken-egg problem.
42
42
 
43
43
  ## Contributing
44
44
 
45
- Use the OS X system Ruby (1.8.7 or 2.0.0). Run `script/tests` often. Open PR's.
45
+ Use the OS X system Ruby (2.0 or newer). Run `script/tests` often. Open PR's.
46
46
  Use the CI.
47
47
 
48
48
  ## Halp!
@@ -1,30 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- $:.unshift File.expand_path("../lib", __FILE__)
4
- require "boxen/version"
5
-
6
3
  Gem::Specification.new do |gem|
7
4
  gem.name = "boxen"
8
- gem.version = Boxen::VERSION
9
- gem.authors = ["John Barnette", "Will Farrington", "David Goodlad"]
10
- gem.email = ["jbarnette@github.com", "wfarr@github.com", "dgoodlad@github.com"]
5
+ gem.version = "3.1.0"
6
+ # Thanks go out to the previous maintainers John Barnette, Will
7
+ # Farrington, David Goodlad and Mike McQuaid for getting this project
8
+ # to where it is today.
9
+ gem.authors = ["Jacob Bednarz"]
10
+ gem.email = ["jacob.bednarz@gmail.com"]
11
11
  gem.description = "Manage Mac development boxes with love (and Puppet)."
12
12
  gem.summary = "You know, for laptops and stuff."
13
13
  gem.homepage = "https://github.com/boxen/boxen"
14
+ gem.license = 'MIT'
14
15
 
15
- gem.files = `git ls-files`.split( $/)
16
- gem.test_files = gem.files.grep(/^test/)
17
- gem.executables = gem.files.grep(/^bin/).map { |bin| File.basename(bin) }
16
+ gem.files = `git ls-files`.split $/
17
+ gem.test_files = gem.files.grep /^test/
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "ansi", "~> 1.4"
21
21
  gem.add_dependency "hiera", "~> 1.0"
22
- gem.add_dependency "highline", "~> 1.6"
22
+ gem.add_dependency "highline", "~> 1.6.0"
23
23
  gem.add_dependency "json_pure", [">= 1.7.7", "< 2.0"]
24
- gem.add_dependency "librarian-puppet", "~> 1.0.0"
24
+ gem.add_dependency "librarian-puppet", "~> 2.2"
25
25
  gem.add_dependency "octokit", "~> 2.7", ">= 2.7.1"
26
- gem.add_dependency "puppet", "~> 3.0"
26
+ gem.add_dependency "puppet", "~> 3.7"
27
27
 
28
- gem.add_development_dependency "minitest", "~> 5.0" # pinned for mocha
28
+ gem.add_development_dependency "minitest", "4.4.0" # pinned for mocha
29
29
  gem.add_development_dependency "mocha", "~> 0.13"
30
30
  end
@@ -1,11 +1,20 @@
1
- require "boxen/util/logging"
1
+ require "ansi"
2
2
 
3
3
  module Boxen
4
4
 
5
5
  # The superclass for preflight and postflight sanity checks.
6
6
 
7
7
  class Check
8
- include Boxen::Util::Logging
8
+
9
+ # A collection of preflight instances for `config`. An instance is
10
+ # created for every constant under `self` that's also a
11
+ # subclass of `self`.
12
+
13
+ def self.checks(config)
14
+ constants.map { |n| const_get n }.
15
+ select { |c| c < self }.
16
+ map { |c| c.new config }
17
+ end
9
18
 
10
19
  # Search `dir` and load all Ruby files under it.
11
20
 
@@ -13,12 +22,16 @@ module Boxen
13
22
  Dir["#{dir}/*.rb"].sort.each { |f| load f }
14
23
  end
15
24
 
25
+ # Check each instance against `config`.
26
+
27
+ def self.run(config)
28
+ checks(config).each { |check| check.run unless check.ok? }
29
+ end
30
+
16
31
  attr_reader :config
17
- attr_reader :command
18
32
 
19
- def initialize(config, command)
20
- @config = config
21
- @command = command
33
+ def initialize(config)
34
+ @config = config
22
35
  end
23
36
 
24
37
  # Is everything good to go? Implemented by subclasses.
@@ -33,9 +46,27 @@ module Boxen
33
46
  raise "Subclasses must implement this method."
34
47
  end
35
48
 
49
+ # A fancier `abort` and `warn`. This will probably really annoy
50
+ # someone at some point because it's overriding a Kernel method,
51
+ # but it's limited to checks.
52
+
53
+ def abort(message, *extras)
54
+ extras << { :color => :red }
55
+ warn message, *extras
56
+ exit 1
57
+ end
58
+
59
+ def warn(message, *extras)
60
+ options = Hash === extras.last ? extras.pop : {}
61
+ color = options[:color] || :yellow
62
+
63
+ $stderr.puts ANSI.send(color) { "--> #{message}" }
64
+
65
+ unless extras.empty?
66
+ extras.each { |line| $stderr.puts " #{line}" }
67
+ end
36
68
 
37
- def debug?
38
- @config.debug?
69
+ $stderr.puts
39
70
  end
40
71
  end
41
72
  end
@@ -1,35 +1,61 @@
1
- require "boxen/command"
2
1
  require "boxen/config"
3
- require "boxen/util/logging"
2
+ require "boxen/flags"
3
+ require "boxen/postflight"
4
+ require "boxen/preflight"
5
+ require "boxen/runner"
6
+ require "boxen/util"
4
7
 
5
8
  module Boxen
6
9
  class CLI
7
- include Boxen::Util::Logging
8
-
9
- def self.run(*args)
10
- new.run(*args)
10
+ attr_reader :config
11
+ attr_reader :flags
12
+ attr_reader :runner
13
+
14
+ def initialize(config, flags)
15
+ @config = config
16
+ @flags = flags
17
+ @runner = Boxen::Runner.new(@config, @flags)
11
18
  end
12
19
 
13
- def initialize
20
+ def run
21
+ if flags.help?
22
+ puts flags
23
+ exit
24
+ end
25
+
26
+ runner.run
14
27
  end
15
28
 
16
- def run(*args)
17
- cmd, *cmd_args = args.flatten
29
+ # Run Boxen by wiring together the command-line flags, config,
30
+ # preflights, Puppet execution, and postflights. Returns Puppet's
31
+ # exit code.
32
+
33
+ def self.run(*args)
34
+ config = Boxen::Config.load
35
+ flags = Boxen::Flags.new args
36
+
37
+ # Apply command-line flags to the config in case we're changing or
38
+ # overriding anything.
39
+ flags.apply config
18
40
 
19
- with_friendly_errors do
20
- config = Boxen::Config.load
21
- status = Boxen::Command.invoke cmd, config, *cmd_args
41
+ if flags.run?
42
+ # Run the preflight checks.
43
+ Boxen::Preflight.run config
22
44
 
23
- status.code
45
+ # Save the config for Puppet (and next time).
46
+ Boxen::Config.save config
24
47
  end
25
- end
26
48
 
27
- private
49
+ # Make the magic happen.
50
+ status = Boxen::CLI.new(config, flags).run
51
+
52
+ if flags.run?
53
+ # Run the postflight checks.
54
+ Boxen::Postflight.run config if status.success?
55
+ end
28
56
 
29
- def with_friendly_errors(&block)
30
- yield
31
- rescue => e
32
- abort "#{e.class.name}: #{e.message}"
57
+ # Return Puppet's exit status.
58
+ return status.code
33
59
  end
34
60
  end
35
61
  end
@@ -25,6 +25,9 @@ module Boxen
25
25
  end
26
26
  end
27
27
 
28
+ keychain = Boxen::Keychain.new config.user
29
+ config.token = keychain.token
30
+
28
31
  if config.enterprise?
29
32
  # configure to talk to GitHub Enterprise
30
33
  Octokit.configure do |c|
@@ -77,19 +80,10 @@ module Boxen
77
80
  def initialize(&block)
78
81
  @fde = true
79
82
  @pull = true
80
- @debug = false
81
83
 
82
84
  yield self if block_given?
83
85
  end
84
86
 
85
- def keychain
86
- @keychain ||= Boxen::Keychain.new self.user
87
- end
88
-
89
- def token
90
- @token ||= keychain.token
91
- end
92
-
93
87
  # Create an API instance using the current user creds. A new
94
88
  # instance is created any time `token` changes.
95
89
 
@@ -100,32 +94,11 @@ module Boxen
100
94
  # Spew a bunch of debug logging? Default is `false`.
101
95
 
102
96
  def debug?
103
- # TODO: fix this
104
97
  !!@debug
105
98
  end
106
99
 
107
100
  attr_writer :debug
108
101
 
109
- def offline?
110
- @offline ||= false
111
- end
112
-
113
- attr_writer :offline
114
-
115
- def report?
116
- # TODO: Actually make this a thing
117
- @report = false
118
- end
119
-
120
- attr_writer :report
121
-
122
- def profile?
123
- #TODO: Actually make this a thing
124
- @profile = true
125
- end
126
-
127
- attr_writer :profile
128
-
129
102
  # A GitHub user's public email.
130
103
 
131
104
  attr_accessor :email
@@ -149,7 +122,7 @@ module Boxen
149
122
  # `BOXEN_HOME` environment variable.
150
123
 
151
124
  def homedir
152
- @homedir ||= (ENV["BOXEN_HOME"] || "/opt/boxen")
125
+ @homedir || ENV["BOXEN_HOME"] || "/opt/boxen"
153
126
  end
154
127
 
155
128
  attr_writer :homedir
@@ -159,7 +132,7 @@ module Boxen
159
132
  # overwritten on every run.
160
133
 
161
134
  def logfile
162
- @logfile ||= (ENV["BOXEN_LOG_FILE"] || "#{repodir}/log/boxen.log")
135
+ @logfile || ENV["BOXEN_LOG_FILE"] || "#{repodir}/log/boxen.log"
163
136
  end
164
137
 
165
138
  attr_writer :logfile
@@ -172,6 +145,46 @@ module Boxen
172
145
 
173
146
  attr_accessor :name
174
147
 
148
+ # Just go through the motions? Default is `false`.
149
+
150
+ def pretend?
151
+ !!@pretend
152
+ end
153
+
154
+ attr_writer :pretend
155
+
156
+ # Run a profiler on Puppet? Default is `false`.
157
+
158
+ def profile?
159
+ !!@profile
160
+ end
161
+
162
+ attr_writer :profile
163
+
164
+ # Enable the Puppet future parser? Default is `false`.
165
+
166
+ def future_parser?
167
+ !!@future_parser
168
+ end
169
+
170
+ attr_writer :future_parser
171
+
172
+ # Enable puppet reports ? Default is `false`.
173
+
174
+ def report?
175
+ !!@report
176
+ end
177
+
178
+ attr_writer :report
179
+
180
+ # Enable generation of dependency graphs.
181
+
182
+ def graph?
183
+ !!@graph
184
+ end
185
+
186
+ attr_writer :graph
187
+
175
188
  # An Array of Boxen::Project entries, one for each project Boxen
176
189
  # knows how to manage.
177
190
  #
@@ -195,7 +208,7 @@ module Boxen
195
208
  # `BOXEN_PUPPET_DIR` environment variable.
196
209
 
197
210
  def puppetdir
198
- @puppetdir ||= (ENV["BOXEN_PUPPET_DIR"] || "/tmp/boxen/puppet")
211
+ @puppetdir || ENV["BOXEN_PUPPET_DIR"] || "/tmp/boxen/puppet"
199
212
  end
200
213
 
201
214
  attr_writer :puppetdir
@@ -204,7 +217,7 @@ module Boxen
204
217
  # `Dir.pwd`. Respects the `BOXEN_REPO_DIR` environment variable.
205
218
 
206
219
  def repodir
207
- @repodir ||= (ENV["BOXEN_REPO_DIR"] || Dir.pwd)
220
+ @repodir || ENV["BOXEN_REPO_DIR"] || Dir.pwd
208
221
  end
209
222
 
210
223
  attr_writer :repodir
@@ -215,7 +228,7 @@ module Boxen
215
228
  # Respects the `BOXEN_REPO_NAME` environment variable.
216
229
 
217
230
  def reponame
218
- override = @reponame ||= ENV["BOXEN_REPO_NAME"]
231
+ override = @reponame || ENV["BOXEN_REPO_NAME"]
219
232
  return override unless override.nil?
220
233
 
221
234
  if File.directory? repodir
@@ -225,7 +238,7 @@ module Boxen
225
238
  # find the path and strip off the .git suffix
226
239
  repo_exp = Regexp.new Regexp.escape(ghuri.host) + "[/:]([^/]+/[^/]+)"
227
240
  if $?.success? && repo_exp.match(url)
228
- @reponame = $1.sub(/\.git$/, "")
241
+ @reponame = $1.sub /\.git$/, ""
229
242
  end
230
243
  end
231
244
  end
@@ -235,7 +248,7 @@ module Boxen
235
248
  # GitHub location (public or GitHub Enterprise)
236
249
 
237
250
  def ghurl
238
- @ghurl ||= (ENV["BOXEN_GITHUB_ENTERPRISE_URL"] || "https://github.com")
251
+ @ghurl || ENV["BOXEN_GITHUB_ENTERPRISE_URL"] || "https://github.com"
239
252
  end
240
253
 
241
254
  attr_writer :ghurl
@@ -243,7 +256,8 @@ module Boxen
243
256
  # Repository URL template (required for GitHub Enterprise)
244
257
 
245
258
  def repotemplate
246
- @repotemplate ||= (ENV["BOXEN_REPO_URL_TEMPLATE"] || "https://github.com/%s")
259
+ default = 'https://github.com/%s'
260
+ @repotemplate || ENV["BOXEN_REPO_URL_TEMPLATE"] || default
247
261
  end
248
262
 
249
263
  attr_writer :repotemplate
@@ -258,7 +272,7 @@ module Boxen
258
272
  # `"/Users/#{user}/src"`.
259
273
 
260
274
  def srcdir
261
- @srcdir ||= (ENV["BOXEN_SRC_DIR"] || "/Users/#{user}/src")
275
+ @srcdir || ENV["BOXEN_SRC_DIR"] || "/Users/#{user}/src"
262
276
  end
263
277
 
264
278
  attr_writer :srcdir
@@ -267,11 +281,15 @@ module Boxen
267
281
  # Respects the `BOXEN_NO_ISSUE` environment variable.
268
282
 
269
283
  def stealth?
270
- @stealth ||= !!ENV["BOXEN_NO_ISSUE"]
284
+ !!ENV["BOXEN_NO_ISSUE"] || @stealth
271
285
  end
272
286
 
273
287
  attr_writer :stealth
274
288
 
289
+ # A GitHub OAuth token. Default is `nil`.
290
+
291
+ attr_reader :token
292
+
275
293
  def token=(token)
276
294
  @token = token
277
295
  @api = nil
@@ -280,7 +298,7 @@ module Boxen
280
298
  # A local user login. Default is the `USER` environment variable.
281
299
 
282
300
  def user
283
- @user ||= ENV["USER"]
301
+ @user || ENV["USER"]
284
302
  end
285
303
 
286
304
  attr_writer :user
@@ -295,7 +313,7 @@ module Boxen
295
313
  # Respects the `BOXEN_S3_HOST` environment variable.
296
314
 
297
315
  def s3host
298
- @s3host ||= (ENV["BOXEN_S3_HOST"] || "s3.amazonaws.com")
316
+ @s3host || ENV["BOXEN_S3_HOST"] || "s3.amazonaws.com"
299
317
  end
300
318
 
301
319
  attr_writer :s3host
@@ -304,7 +322,7 @@ module Boxen
304
322
  # Respects the `BOXEN_S3_BUCKET` environment variable.
305
323
 
306
324
  def s3bucket
307
- @s3bucket ||= (ENV["BOXEN_S3_BUCKET"] || "boxen-downloads")
325
+ @s3bucket || ENV["BOXEN_S3_BUCKET"] || "boxen-downloads"
308
326
  end
309
327
 
310
328
  attr_writer :s3bucket