gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
Revisión | b2f398418e58f76b7354bac497d2fd8592dddf85 (tree) |
---|---|
Tiempo | 2018-04-08 14:17:21 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
例外を投げるようにした
@@ -8,6 +8,13 @@ | ||
8 | 8 | |
9 | 9 | import Foundation |
10 | 10 | |
11 | +enum CarthageError: Error { | |
12 | + | |
13 | + case commandNotFound | |
14 | + | |
15 | + case commandFail | |
16 | +} | |
17 | + | |
11 | 18 | final class Carthage { |
12 | 19 | |
13 | 20 | let baseURL: URL |
@@ -42,7 +49,7 @@ final class Carthage { | ||
42 | 49 | return true |
43 | 50 | } |
44 | 51 | |
45 | - func execute() { | |
52 | + func execute() throws { | |
46 | 53 | |
47 | 54 | guard let cartfile = cartfileURL else { |
48 | 55 |
@@ -51,15 +58,15 @@ final class Carthage { | ||
51 | 58 | |
52 | 59 | guard let carthageURL = carthageURL else { |
53 | 60 | |
54 | - return | |
61 | + throw CarthageError.commandNotFound | |
55 | 62 | } |
56 | 63 | |
57 | - let log = LogStocker("carthage.log") | |
58 | - | |
59 | 64 | let carthage = Process() <<< carthageURL.path <<< ["update"] |
60 | 65 | carthage.currentDirectoryPath = cartfile.deletingLastPathComponent().path |
61 | 66 | |
62 | 67 | carthage >>> { output, error in |
68 | + | |
69 | + let log = LogStocker("carthage.log") | |
63 | 70 | log?.write(output.data) |
64 | 71 | log?.write(error.data) |
65 | 72 | } |
@@ -67,7 +74,7 @@ final class Carthage { | ||
67 | 74 | |
68 | 75 | if carthage.terminationStatus != 0 { |
69 | 76 | |
70 | - log?.write("Carthage error exit with status \(carthage.terminationStatus)") | |
77 | + throw CarthageError.commandFail | |
71 | 78 | } |
72 | 79 | } |
73 | 80 | } |
@@ -112,7 +112,10 @@ extension ViewController { | ||
112 | 112 | case .none: |
113 | 113 | self.message = "Finish cloning" |
114 | 114 | |
115 | - self.carthage(gitCloner.repository) | |
115 | + guard self.carthage(gitCloner.repository) else { | |
116 | + | |
117 | + return | |
118 | + } | |
116 | 119 | |
117 | 120 | self.build(gitCloner.repository) |
118 | 121 |
@@ -127,20 +130,31 @@ extension ViewController { | ||
127 | 130 | } |
128 | 131 | } |
129 | 132 | |
130 | - private func carthage(_ url: URL) { | |
133 | + private func carthage(_ url: URL) -> Bool { | |
131 | 134 | |
132 | 135 | message = "Checking Carthage." |
133 | 136 | |
134 | - let carthage = Carthage(url) | |
135 | - | |
136 | - guard carthage.checkCarthage() else { | |
137 | + do { | |
138 | + | |
139 | + let carthage = Carthage(url) | |
140 | + | |
141 | + guard carthage.checkCarthage() else { | |
142 | + | |
143 | + return true | |
144 | + } | |
145 | + | |
146 | + message = "Building frameworks with Carthage." | |
137 | 147 | |
138 | - return | |
148 | + try carthage.execute() | |
149 | + | |
150 | + return true | |
151 | + | |
152 | + } catch { | |
153 | + | |
154 | + message = "Fail to carthage." | |
155 | + | |
156 | + return false | |
139 | 157 | } |
140 | - | |
141 | - message = "Building frameworks with Carthage." | |
142 | - | |
143 | - carthage.execute() | |
144 | 158 | } |
145 | 159 | |
146 | 160 | private func build(_ url: URL) { |