|
1 | 1 | module Terminal.Init exposing |
2 | 2 | ( Config |
| 3 | + , Error (..) |
3 | 4 | , run |
| 5 | + , prettifyError |
4 | 6 | ) |
5 | 7 |
|
6 | 8 | import CLI.PrettyPrinter as PP |
@@ -47,7 +49,7 @@ type Error |
47 | 49 | | InstallError PackageInstall.PackageInstallError |
48 | 50 |
|
49 | 51 |
|
50 | | -run : Config -> Cmd a |
| 52 | +run : Config -> Task Error {} |
51 | 53 | run config = |
52 | 54 | let |
53 | 55 | grenJsonExists = |
@@ -103,11 +105,6 @@ run config = |
103 | 105 | else |
104 | 106 | Stream.Log.line config.stdout "Ok, I won't do anything." |
105 | 107 | ) |
106 | | - |> Task.onError |
107 | | - (\err -> |
108 | | - Stream.Log.line config.stdout (displayError { useColor = config.useColor } err) |
109 | | - ) |
110 | | - |> Task.execute |
111 | 108 |
|
112 | 109 |
|
113 | 110 | init : Config -> Task Error {} |
@@ -240,81 +237,80 @@ generateGrenJson config deps = |
240 | 237 | ) |
241 | 238 |
|
242 | 239 |
|
243 | | -displayError : { useColor : Bool } -> Error -> String |
244 | | -displayError printOpts err = |
245 | | - Terminal.Help.prettyPrint printOpts <| |
246 | | - when err is |
247 | | - AlreadyInitialized -> |
248 | | - Terminal.Help.report |
249 | | - "EXISTING PROJECT" |
250 | | - Nothing |
251 | | - (PP.verticalBlock |
252 | | - [ PP.words "You already have a gren.json file, so there's nothing for me to initialize!" |
253 | | - , PP.empty |
254 | | - , PP.block |
255 | | - [ PP.text "Maybe " |
256 | | - , PP.color PP.Green (Terminal.Help.makeLink "init") |
257 | | - , PP.text " " |
258 | | - , PP.words "can help you figure out what to do next?" |
259 | | - ] |
| 240 | +prettifyError : Error -> PP.Document |
| 241 | +prettifyError err = |
| 242 | + when err is |
| 243 | + AlreadyInitialized -> |
| 244 | + Terminal.Help.report |
| 245 | + "EXISTING PROJECT" |
| 246 | + Nothing |
| 247 | + (PP.verticalBlock |
| 248 | + [ PP.words "You already have a gren.json file, so there's nothing for me to initialize!" |
| 249 | + , PP.empty |
| 250 | + , PP.block |
| 251 | + [ PP.text "Maybe " |
| 252 | + , PP.color PP.Green (Terminal.Help.makeLink "init") |
| 253 | + , PP.text " " |
| 254 | + , PP.words "can help you figure out what to do next?" |
260 | 255 | ] |
261 | | - ) |
| 256 | + ] |
| 257 | + ) |
262 | 258 |
|
263 | | - FileSystemFailure fsErr -> |
264 | | - Terminal.Help.report |
265 | | - "FILESYSTEM ERROR" |
266 | | - (Just <| FileSystem.errorPath fsErr) |
267 | | - (PP.verticalBlock |
268 | | - [ PP.words "An unexpected error occured when accessing the filesystem." |
269 | | - , PP.empty |
270 | | - , PP.words "The error provided by the operating system is:" |
271 | | - , PP.empty |
272 | | - , PP.words (FileSystem.errorToString fsErr) |
273 | | - |> PP.color PP.Red |
274 | | - |> PP.indent |
275 | | - , PP.empty |
276 | | - , PP.words "Verify that you have access to this path. If the error persist, consider submitting a bug report." |
277 | | - ] |
278 | | - ) |
| 259 | + FileSystemFailure fsErr -> |
| 260 | + Terminal.Help.report |
| 261 | + "FILESYSTEM ERROR" |
| 262 | + (Just <| FileSystem.errorPath fsErr) |
| 263 | + (PP.verticalBlock |
| 264 | + [ PP.words "An unexpected error occured when accessing the filesystem." |
| 265 | + , PP.empty |
| 266 | + , PP.words "The error provided by the operating system is:" |
| 267 | + , PP.empty |
| 268 | + , PP.words (FileSystem.errorToString fsErr) |
| 269 | + |> PP.color PP.Red |
| 270 | + |> PP.indent |
| 271 | + , PP.empty |
| 272 | + , PP.words "Verify that you have access to this path. If the error persist, consider submitting a bug report." |
| 273 | + ] |
| 274 | + ) |
279 | 275 |
|
280 | | - PromptError streamError -> |
281 | | - Terminal.Help.report |
282 | | - "STREAM ERROR" |
283 | | - Nothing |
284 | | - (PP.verticalBlock |
285 | | - [ PP.words "An unexpected error occured with either the standard output or standard input streams." |
286 | | - , PP.empty |
287 | | - , PP.words "The error is:" |
288 | | - , PP.empty |
289 | | - , PP.words (Stream.errorToString streamError) |
290 | | - |> PP.color PP.Red |
291 | | - |> PP.indent |
292 | | - , PP.empty |
293 | | - , PP.words "This is most likely a bug. Consider submitting a bug report." |
294 | | - ] |
295 | | - ) |
| 276 | + PromptError streamError -> |
| 277 | + Terminal.Help.report |
| 278 | + "STREAM ERROR" |
| 279 | + Nothing |
| 280 | + (PP.verticalBlock |
| 281 | + [ PP.words "An unexpected error occured with either the standard output or standard input streams." |
| 282 | + , PP.empty |
| 283 | + , PP.words "The error is:" |
| 284 | + , PP.empty |
| 285 | + , PP.words (Stream.errorToString streamError) |
| 286 | + |> PP.color PP.Red |
| 287 | + |> PP.indent |
| 288 | + , PP.empty |
| 289 | + , PP.words "This is most likely a bug. Consider submitting a bug report." |
| 290 | + ] |
| 291 | + ) |
296 | 292 |
|
297 | | - CouldNotRetrieveVersions { packageName, error } -> |
298 | | - Git.report |
299 | | - "FAILED TO LOAD DEPENDENCIES" |
300 | | - ("I tried to find the latest compatible versions of the " ++ PackageName.toString packageName) |
301 | | - error |
| 293 | + CouldNotRetrieveVersions { packageName, error } -> |
| 294 | + Git.report |
| 295 | + "FAILED TO LOAD DEPENDENCIES" |
| 296 | + ("I tried to find the latest compatible versions of the " ++ PackageName.toString packageName) |
| 297 | + error |
302 | 298 |
|
303 | | - NoVersionFound packageName -> |
304 | | - Terminal.Help.report |
305 | | - "FAILED TO LOAD DEPENDENCIES" |
306 | | - Nothing |
307 | | - (PP.verticalBlock |
308 | | - [ PP.words "I tried to find the latest compatible versions of the" |
309 | | - , PP.text " " |
310 | | - , PP.text (PackageName.toString packageName) |
311 | | - |> PP.color PP.Green |
312 | | - , PP.text " " |
313 | | - , PP.words "but failed to find any versions for that package!" |
314 | | - , PP.empty |
315 | | - , PP.words "This is most likely a bug. Consider submitting a bug report." |
316 | | - ] |
317 | | - ) |
| 299 | + NoVersionFound packageName -> |
| 300 | + Terminal.Help.report |
| 301 | + "FAILED TO LOAD DEPENDENCIES" |
| 302 | + Nothing |
| 303 | + (PP.verticalBlock |
| 304 | + [ PP.words "I tried to find the latest compatible versions of the" |
| 305 | + , PP.text " " |
| 306 | + , PP.text (PackageName.toString packageName) |
| 307 | + |> PP.color PP.Green |
| 308 | + , PP.text " " |
| 309 | + , PP.words "but failed to find any versions for that package!" |
| 310 | + , PP.empty |
| 311 | + , PP.words "This is most likely a bug. Consider submitting a bug report." |
| 312 | + ] |
| 313 | + ) |
318 | 314 |
|
319 | | - InstallError installError -> |
320 | | - PackageInstall.prettifyError installError |
| 315 | + InstallError installError -> |
| 316 | + PackageInstall.prettifyError installError |
0 commit comments