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 +4 -4
- data/lib/kapost/bootstrapper.rb +30 -14
- data/lib/kapost/bootstrapper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48e8b54eec082d2fa5143727675462ce8892f18f
|
4
|
+
data.tar.gz: 8da354bc5d20bf8f6f64df870a4bc0723c3b300f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20d387ab90761ce8008e2798ffe412e5a8cc2be2a10bc23abedef5fb3c4cbe251f14a7e2de443c16e03b3c7c232e2f542ae01914720f82a10785b740fb374b9a
|
7
|
+
data.tar.gz: f8b88d86e2a17a31ce7962ac54cfccf6456c9757e7fc4a7792e3b13c7f1e8c1f8aa751d2dd780dc7ab225ae3e2c359682223a5023f27dd91605952e2ef3d308d
|
data/lib/kapost/bootstrapper.rb
CHANGED
@@ -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
|
16
|
-
|
17
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|