on master help sign in
Give a more helpful message on `elm install`
f66de6cEvan Czaplicki
builder/src/Elm/Install.hs+3−2
@@ -26,6 +26,7 @@ import qualified Elm.Project.Root as Root
26import Reporting.Doc ((<>), (<+>))
26import Reporting.Doc ((<>), (<+>))
27import qualified Reporting.Doc as D
27import qualified Reporting.Doc as D
28import qualified Reporting.Exit as Exit
28import qualified Reporting.Exit as Exit
29+import qualified Reporting.Exit.Install as E
29import qualified Reporting.Task as Task
30import qualified Reporting.Task as Task
30
31
31
32
@@ -148,7 +149,7 @@ addToApp pkg info@(Project.AppInfo _ _ deps tests trans) =
148
149
149 Nothing ->
150 Nothing ->
150 do badNames <- filterM isBadElm (pkg : Map.keys old)
151 do badNames <- filterM isBadElm (pkg : Map.keys old)
151− lift $ Task.throw (Exit.NoSolution badNames)
152+ lift $ Task.throw (Exit.Install (E.NoSolution badNames))
152
153
153
154
154addToAppHelp :: Name -> Project.AppInfo -> Solver.Solver (Map Name Version)
155addToAppHelp :: Name -> Project.AppInfo -> Solver.Solver (Map Name Version)
@@ -189,7 +190,7 @@ addToPkg pkg info@(Project.PkgInfo _ _ _ _ _ deps tests _) =
189 Nothing ->
190 Nothing ->
190 do let pkgs = Map.keys deps ++ Map.keys tests
191 do let pkgs = Map.keys deps ++ Map.keys tests
191 badNames <- filterM isBadElm (pkg : pkgs)
192 badNames <- filterM isBadElm (pkg : pkgs)
192− lift $ Task.throw (Exit.NoSolution badNames)
193+ lift $ Task.throw (Exit.Install (E.NoSolution badNames))
193
194
194
195
195addToPkgHelp :: Name -> Project.PkgInfo -> Solver.Solver (Map Name Constraint)
196addToPkgHelp :: Name -> Project.PkgInfo -> Solver.Solver (Map Name Constraint)
builder/src/Reporting/Exit.hs+5−35
@@ -8,9 +8,7 @@ module Reporting.Exit
8 where
8 where
9
9
10
10
11−import qualified Elm.Compiler as Compiler
12import qualified Elm.Compiler.Module as Module
11import qualified Elm.Compiler.Module as Module
13−import qualified Elm.Package as Pkg
14import qualified Json.Encode as Encode
12import qualified Json.Encode as Encode
15import qualified Reporting.Doc as D
13import qualified Reporting.Doc as D
16import qualified Reporting.Exit.Assets as Asset
14import qualified Reporting.Exit.Assets as Asset
@@ -22,6 +20,7 @@ import qualified Reporting.Exit.Diff as Diff
22import qualified Reporting.Exit.Help as Help
20import qualified Reporting.Exit.Help as Help
23import qualified Reporting.Exit.Http as Http
21import qualified Reporting.Exit.Http as Http
24import qualified Reporting.Exit.Make as Make
22import qualified Reporting.Exit.Make as Make
23+import qualified Reporting.Exit.Install as Install
25import qualified Reporting.Exit.Publish as Publish
24import qualified Reporting.Exit.Publish as Publish
26
25
27
26
@@ -39,12 +38,10 @@ data Exit
39 | Deps Deps.Exit
38 | Deps Deps.Exit
40 | Diff Diff.Exit
39 | Diff Diff.Exit
41 | Make Make.Exit
40 | Make Make.Exit
41+ | Install Install.Exit
42 | Publish Publish.Exit
42 | Publish Publish.Exit
43 | BadHttp String Http.Exit
43 | BadHttp String Http.Exit
44
44
45− -- misc
46− | NoSolution [Pkg.Name]
47−
48
45
49
46
50-- RENDERERS
47-- RENDERERS
@@ -116,38 +113,11 @@ toReport exit =
116 Make makeExit ->
113 Make makeExit ->
117 Make.toReport makeExit
114 Make.toReport makeExit
118
115
116+ Install installExit ->
117+ Install.toReport installExit
118+
119 Publish publishExit ->
119 Publish publishExit ->
120 Publish.toReport publishExit
120 Publish.toReport publishExit
121
121
122 BadHttp url httpExit ->
122 BadHttp url httpExit ->
123 Http.toReport url httpExit
123 Http.toReport url httpExit
124−
125− NoSolution badPackages ->
126− case badPackages of
127− [] ->
128− Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
129− "This usually happens if you try to modify dependency constraints by\
130− \ hand. I recommend deleting any dependency you added recently (or all\
131− \ of them if things are bad) and then adding them again with:"
132− [ D.indent 4 $ D.green "elm install"
133− , D.reflow $
134− "And do not be afaid to ask for help on Slack if you get stuck!"
135− ]
136−
137− _:_ ->
138− Help.report "OLD DEPENDENCIES" (Just "elm.json")
139− ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
140− )
141− [ D.indent 4 $ D.vcat $ map (D.red . D.fromString . Pkg.toString) badPackages
142− , D.reflow $
143− "This may be because it is not upgraded yet. It may be because a\
144− \ better solution came along, so there was no need to upgrade it.\
145− \ Etc. Try asking around on Slack to learn more about the topic."
146− , D.toSimpleNote
147− "Whatever the case, please be kind to the relevant package authors! Having\
148− \ friendly interactions with users is great motivation, and conversely, getting\
149− \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
150− \ authors are humans with families, friends, jobs, vacations, responsibilities,\
151− \ goals, etc. They face obstacles outside of their technical work you will never\
152− \ know about, so please assume the best and try to be patient and supportive!"
153− ]
builder/src/Reporting/Exit/Install.hsnew file+82
@@ -0,0 +1,82 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+module Reporting.Exit.Install
3+ ( Exit(..)
4+ , toReport
5+ )
6+ where
7+
8+
9+import qualified Elm.Compiler as Compiler
10+import qualified Elm.Package as Pkg
11+import qualified Reporting.Doc as D
12+import qualified Reporting.Exit.Help as Help
13+
14+
15+
16+-- EXITS
17+
18+
19+data Exit
20+ = NoArgs FilePath
21+ | NoSolution [Pkg.Name]
22+
23+
24+
25+-- TO REPORT
26+
27+
28+toReport :: Exit -> Help.Report
29+toReport exit =
30+ case exit of
31+ NoArgs cacheDir ->
32+ Help.report "INSTALL WHAT?" Nothing
33+ "I am expecting commands like:"
34+ [ D.green $ D.indent 4 $ D.vcat $
35+ [ "elm install elm-lang/http"
36+ , "elm install elm-lang/json"
37+ , "elm install elm-lang/random"
38+ ]
39+ , D.toFancyHint
40+ ["In","JavaScript","folks","run","`npm install`","to","start","projects."
41+ ,"\"Gotta","download","everything!\"","But","why","download","packages"
42+ ,"again","and","again?","Instead,","Elm","caches","packages","in"
43+ ,D.dullyellow (D.fromString cacheDir)
44+ ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
45+ ,"Elm","projects","check","that","cache","before","trying","the","internet."
46+ ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
47+ ,"easier","to","work","offline.","As","a","result"
48+ ,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
49+ ,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
50+ ,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
51+ ]
52+ ]
53+
54+ NoSolution badPackages ->
55+ case badPackages of
56+ [] ->
57+ Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
58+ "This usually happens if you try to modify dependency constraints by\
59+ \ hand. I recommend deleting any dependency you added recently (or all\
60+ \ of them if things are bad) and then adding them again with:"
61+ [ D.indent 4 $ D.green "elm install"
62+ , D.reflow $
63+ "And do not be afaid to ask for help on Slack if you get stuck!"
64+ ]
65+
66+ _:_ ->
67+ Help.report "OLD DEPENDENCIES" (Just "elm.json")
68+ ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
69+ )
70+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromString . Pkg.toString) badPackages
71+ , D.reflow $
72+ "This may be because it is not upgraded yet. It may be because a\
73+ \ better solution came along, so there was no need to upgrade it.\
74+ \ Etc. Try asking around on Slack to learn more about the topic."
75+ , D.toSimpleNote
76+ "Whatever the case, please be kind to the relevant package authors! Having\
77+ \ friendly interactions with users is great motivation, and conversely, getting\
78+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
79+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
80+ \ goals, etc. They face obstacles outside of their technical work you will never\
81+ \ know about, so please assume the best and try to be patient and supportive!"
82+ ]
elm.cabal+1
@@ -118,6 +118,7 @@ Executable elm
118 Reporting.Exit.Help,
118 Reporting.Exit.Help,
119 Reporting.Exit.Http,
119 Reporting.Exit.Http,
120 Reporting.Exit.Make,
120 Reporting.Exit.Make,
121+ Reporting.Exit.Install,
121 Reporting.Exit.Publish,
122 Reporting.Exit.Publish,
122 Reporting.Progress,
123 Reporting.Progress,
123 Reporting.Progress.Bar,
124 Reporting.Progress.Bar,
ui/terminal/src/Install.hs+22−4
@@ -1,8 +1,14 @@
1−module Install (run) where
1+module Install
2+ ( Args(..)
3+ , run
4+ )
5+ where
2
6
3
7
4import qualified Elm.Install as Install
8import qualified Elm.Install as Install
5import qualified Elm.Package as Pkg
9import qualified Elm.Package as Pkg
10+import qualified Reporting.Exit as Exit
11+import qualified Reporting.Exit.Install as E
6import qualified Reporting.Task as Task
12import qualified Reporting.Task as Task
7import qualified Reporting.Progress.Terminal as Terminal
13import qualified Reporting.Progress.Terminal as Terminal
8
14
@@ -11,7 +17,19 @@ import qualified Reporting.Progress.Terminal as Terminal
11-- RUN
17-- RUN
12
18
13
19
20+data Args
21+ = NoArgs
14−run :: Pkg.Name -> () -> IO ()
22+ | Install Pkg.Name
23+
24+
25+run :: Args -> () -> IO ()
15−run pkg () =
26+run args () =
16 do reporter <- Terminal.create
27 do reporter <- Terminal.create
28+ Task.run reporter $
29+ case args of
30+ NoArgs ->
31+ do cacheDir <- Task.getPackageCacheDir
32+ Task.throw (Exit.Install (E.NoArgs cacheDir))
33+
34+ Install pkg ->
17− Task.run reporter $ Install.install pkg
35+ Install.install pkg
ui/terminal/src/Main.hs+7−1
@@ -213,8 +213,14 @@ install =
213 "What if two projects use different versions of the same package? No problem!\
213 "What if two projects use different versions of the same package? No problem!\
214 \ Each project is independent, so there cannot be conflics like that!"
214 \ Each project is independent, so there cannot be conflics like that!"
215 ]
215 ]
216+
217+ installArgs =
218+ oneOf
219+ [ require0 Install.NoArgs
220+ , require1 Install.Install package
221+ ]
216 in
222 in
217− Interface "install" (Common summary) details example (required package) noFlags Install.run
223+ Interface "install" (Common summary) details example installArgs noFlags Install.run
218
224
219
225
220
226