kapost-bootstrapper 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4384c1374a0925ec426e81e7cb8d4d1afef06c99
4
- data.tar.gz: 7f0f93d73a2d7add9fea9c65e102293829a458d1
3
+ metadata.gz: 48e8b54eec082d2fa5143727675462ce8892f18f
4
+ data.tar.gz: 8da354bc5d20bf8f6f64df870a4bc0723c3b300f
5
5
  SHA512:
6
- metadata.gz: 9fc89d09ef1df3f23950ccaba5292a4b331f7b16a6615a0bc527ceac74ece617671648341a5193b685f5bab1aed9bf1d9906215f7473a0aa1295d9a4ba18c031
7
- data.tar.gz: c0ccc02adc2e9f5947dbc2dba251b67bc39ea07aa4f447bc26e92e7c0ac8e3bea04ad98fcea12771fe73b37c7d74d9f45b526a1efdeb8e10f364eb04aa195aec
6
+ metadata.gz: 20d387ab90761ce8008e2798ffe412e5a8cc2be2a10bc23abedef5fb3c4cbe251f14a7e2de443c16e03b3c7c232e2f542ae01914720f82a10785b740fb374b9a
7
+ data.tar.gz: f8b88d86e2a17a31ce7962ac54cfccf6456c9757e7fc4a7792e3b13c7f1e8c1f8aa751d2dd780dc7ab225ae3e2c359682223a5023f27dd91605952e2ef3d308d
@@ -3,6 +3,18 @@ require "open3"
3
3
  module Kapost
4
4
  # Application dependency installer for this Rails application.
5
5
  class Bootstrapper
6
+
7
+ class CommandFailedError < StandardError
8
+ attr_reader :command, :status
9
+ def initialize(command, status)
10
+ @command, @status = command, status
11
+ end
12
+
13
+ def message
14
+ "Command `#{cmd}` failed with status #{status}"
15
+ end
16
+ end
17
+
6
18
  def initialize(cli: Open3, printer: $stdout, platform: RUBY_PLATFORM, shell: Kernel, &block)
7
19
  @cli = cli
8
20
  @printer = printer
@@ -12,20 +24,18 @@ module Kapost
12
24
  run(&block) if block_given?
13
25
  end
14
26
 
15
- def check(command, help = nil, version: nil, &block)
16
- success = say(label(command, version)) do
17
- if block_given?
18
- yield
19
- else
20
- installed?(command) and (!version or right_version?(command, version))
21
- end
22
- end
27
+ def default_check(command, version)
28
+ installed?(command) and (!version or right_version?(command, version))
29
+ end
23
30
 
24
- unless success
25
- say(help) if help
26
- shell.exit 1
27
- end
28
- success
31
+ def check(command, help = nil, version: nil)
32
+ say(label(command, version)) do
33
+ begin
34
+ block_given? ? yield : default_check(command, version)
35
+ rescue CommandFailedError => ex
36
+ die help, exception: ex
37
+ end
38
+ end or die(help)
29
39
  end
30
40
 
31
41
  def check_bundler
@@ -68,10 +78,16 @@ module Kapost
68
78
  say(cmd.join(" ")) if options[:verbose]
69
79
  result = system(*cmd)
70
80
  status = $?
71
- fail "Command `#{cmd.join(' ')}` failed with status #{status.exitstatus}" unless result
81
+ raise CommandFailedError, cmd.join(" "), status.exitstatus unless result
72
82
  result
73
83
  end
74
84
 
85
+ def die(help, exception: nil)
86
+ say(exception.message) if exception
87
+ say(help) if help
88
+ shell.exit 1
89
+ end
90
+
75
91
  def osx(&block)
76
92
  run(&block) if os == :macosx
77
93
  end
@@ -1,5 +1,5 @@
1
1
  module Kapost
2
2
  class Bootstrapper
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapost-bootstrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas