on master help sign in
Give a more helpful message on `elm install`
commitf66de6c4ce8873a5a911a34a8231e82da8b70131 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 10 May 2018, 19:21 (8 years ago) parent8d95c61
6 files changed+120−42
builder/src/Elm/Install.hs+3−2 builder/src/Reporting/Exit.hs+5−35 builder/src/Reporting/Exit/Install.hs+82 elm.cabal+1 ui/terminal/src/Install.hs+22−4 ui/terminal/src/Main.hs+7−1
builder/src/Elm/Install.hs+3−2
@@ -26,6 +26,7 @@ import qualified Elm.Project.Root as Root
2626import Reporting.Doc ((<>), (<+>))
2727import qualified Reporting.Doc as D
2828import qualified Reporting.Exit as Exit
29+import qualified Reporting.Exit.Install as E
2930import qualified Reporting.Task as Task
3031
3132
@@ -148,7 +149,7 @@ addToApp pkg info@(Project.AppInfo _ _ deps tests trans) =
148149
149150 Nothing ->
150151 do badNames <- filterM isBadElm (pkg : Map.keys old)
151− lift $ Task.throw (Exit.NoSolution badNames)
152+ lift $ Task.throw (Exit.Install (E.NoSolution badNames))
152153
153154
154155addToAppHelp :: Name -> Project.AppInfo -> Solver.Solver (Map Name Version)
@@ -189,7 +190,7 @@ addToPkg pkg info@(Project.PkgInfo _ _ _ _ _ deps tests _) =
189190 Nothing ->
190191 do let pkgs = Map.keys deps ++ Map.keys tests
191192 badNames <- filterM isBadElm (pkg : pkgs)
192− lift $ Task.throw (Exit.NoSolution badNames)
193+ lift $ Task.throw (Exit.Install (E.NoSolution badNames))
193194
194195
195196addToPkgHelp :: Name -> Project.PkgInfo -> Solver.Solver (Map Name Constraint)
builder/src/Reporting/Exit.hs+5−35
@@ -8,9 +8,7 @@ module Reporting.Exit
88 where
99
1010
11−import qualified Elm.Compiler as Compiler
1211import qualified Elm.Compiler.Module as Module
13−import qualified Elm.Package as Pkg
1412import qualified Json.Encode as Encode
1513import qualified Reporting.Doc as D
1614import qualified Reporting.Exit.Assets as Asset
@@ -22,6 +20,7 @@ import qualified Reporting.Exit.Diff as Diff
2220import qualified Reporting.Exit.Help as Help
2321import qualified Reporting.Exit.Http as Http
2422import qualified Reporting.Exit.Make as Make
23+import qualified Reporting.Exit.Install as Install
2524import qualified Reporting.Exit.Publish as Publish
2625
2726
@@ -39,12 +38,10 @@ data Exit
3938 | Deps Deps.Exit
4039 | Diff Diff.Exit
4140 | Make Make.Exit
41+ | Install Install.Exit
4242 | Publish Publish.Exit
4343 | BadHttp String Http.Exit
4444
45− -- misc
46− | NoSolution [Pkg.Name]
47−
4845
4946
5047-- RENDERERS
@@ -116,38 +113,11 @@ toReport exit =
116113 Make makeExit ->
117114 Make.toReport makeExit
118115
116+ Install installExit ->
117+ Install.toReport installExit
118+
119119 Publish publishExit ->
120120 Publish.toReport publishExit
121121
122122 BadHttp url httpExit ->
123123 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
118118 Reporting.Exit.Help,
119119 Reporting.Exit.Http,
120120 Reporting.Exit.Make,
121+ Reporting.Exit.Install,
121122 Reporting.Exit.Publish,
122123 Reporting.Progress,
123124 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
26
37
48import qualified Elm.Install as Install
59import qualified Elm.Package as Pkg
10+import qualified Reporting.Exit as Exit
11+import qualified Reporting.Exit.Install as E
612import qualified Reporting.Task as Task
713import qualified Reporting.Progress.Terminal as Terminal
814
@@ -11,7 +17,19 @@ import qualified Reporting.Progress.Terminal as Terminal
1117-- RUN
1218
1319
14−run :: Pkg.Name -> () -> IO ()
15−run pkg () =
20+data Args
21+ = NoArgs
22+ | Install Pkg.Name
23+
24+
25+run :: Args -> () -> IO ()
26+run args () =
1627 do reporter <- Terminal.create
17− Task.run reporter $ Install.install pkg
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 ->
35+ Install.install pkg
ui/terminal/src/Main.hs+7−1
@@ -213,8 +213,14 @@ install =
213213 "What if two projects use different versions of the same package? No problem!\
214214 \ Each project is independent, so there cannot be conflics like that!"
215215 ]
216+
217+ installArgs =
218+ oneOf
219+ [ require0 Install.NoArgs
220+ , require1 Install.Install package
221+ ]
216222 in
217− Interface "install" (Common summary) details example (required package) noFlags Install.run
223+ Interface "install" (Common summary) details example installArgs noFlags Install.run
218224
219225
220226