on 42f3721 help sign in
118 lines 2.7 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit
3 ( Exit(..)
4 , toString
5 , toStderr
6 , toJson
7 )
8 where
11import qualified Elm.Compiler.Module as Module
12import qualified Json.Encode as Encode
13import qualified Reporting.Doc as D
14import qualified Reporting.Exit.Assets as Asset
15import qualified Reporting.Exit.Bump as Bump
16import qualified Reporting.Exit.Compile as Compile
17import qualified Reporting.Exit.Crawl as Crawl
18import qualified Reporting.Exit.Deps as Deps
19import qualified Reporting.Exit.Diff as Diff
20import qualified Reporting.Exit.Help as Help
21import qualified Reporting.Exit.Http as Http
22import qualified Reporting.Exit.Make as Make
23import qualified Reporting.Exit.Init as Init
24import qualified Reporting.Exit.Install as Install
25import qualified Reporting.Exit.Publish as Publish
29-- ALL POSSIBLE ERRORS
32data Exit
33 = NoElmJson
34 | Assets Asset.Exit
35 | Bump Bump.Exit
36 | Compile Compile.Exit [Compile.Exit]
37 | Crawl Crawl.Exit
38 | Cycle [Module.Raw] -- TODO write docs to help with this scenario
39 | Deps Deps.Exit
40 | Diff Diff.Exit
41 | Make Make.Exit
42 | Init Init.Exit
43 | Install Install.Exit
44 | Publish Publish.Exit
45 | BadHttp String Http.Exit
49-- RENDERERS
52toString :: Exit -> String
53toString exit =
54 Help.toString (Help.reportToDoc (toReport exit))
57toStderr :: Exit -> IO ()
58toStderr exit =
59 Help.toStderr (Help.reportToDoc (toReport exit))
62toJson :: Exit -> Encode.Value
63toJson exit =
64 Help.reportToJson (toReport exit)
67toReport :: Exit -> Help.Report
68toReport exit =
69 case exit of
70 NoElmJson ->
71 Help.report "NO elm.json FILE" Nothing
72 "It looks like you are starting a new Elm project. Very exciting! Try running:"
73 [ D.indent 4 $ D.green $ "elm init"
74 , D.reflow $
75 "It will help you get set up. It is really simple!"
76 ]
78 Assets assetExit ->
79 Asset.toReport assetExit
81 Bump bumpExit ->
82 Bump.toReport bumpExit
84 Compile e es ->
85 Help.compilerReport e es
87 Crawl crawlExit ->
88 Crawl.toReport crawlExit
90 Cycle names ->
91 Help.report "IMPORT CYCLE" Nothing
92 "Your module imports form a cycle:"
93 [ D.cycle 4 names
94 , D.reflow $
95 "Learn more about why this is disallowed and how to break cycles here:"
96 ++ D.makeLink "import-cycles"
97 ]
99 Deps depsExit ->
100 Deps.toReport depsExit
102 Diff commandsExit ->
103 Diff.toReport commandsExit
105 Make makeExit ->
106 Make.toReport makeExit
108 Init initExit ->
109 Init.toReport initExit
111 Install installExit ->
112 Install.toReport installExit
114 Publish publishExit ->
115 Publish.toReport publishExit
117 BadHttp url httpExit ->
118 Http.toReport url httpExit