Give a more helpful message on elm install

This commit is contained in:
Evan Czaplicki 2018-05-10 19:21:48 +02:00
parent 8d95c612b0
commit f66de6c4ce
6 changed files with 120 additions and 42 deletions

View File

@ -26,6 +26,7 @@ import qualified Elm.Project.Root as Root
import Reporting.Doc ((<>), (<+>))
import qualified Reporting.Doc as D
import qualified Reporting.Exit as Exit
import qualified Reporting.Exit.Install as E
import qualified Reporting.Task as Task
@ -148,7 +149,7 @@ addToApp pkg info@(Project.AppInfo _ _ deps tests trans) =
Nothing ->
do badNames <- filterM isBadElm (pkg : Map.keys old)
lift $ Task.throw (Exit.NoSolution badNames)
lift $ Task.throw (Exit.Install (E.NoSolution badNames))
addToAppHelp :: Name -> Project.AppInfo -> Solver.Solver (Map Name Version)
@ -189,7 +190,7 @@ addToPkg pkg info@(Project.PkgInfo _ _ _ _ _ deps tests _) =
Nothing ->
do let pkgs = Map.keys deps ++ Map.keys tests
badNames <- filterM isBadElm (pkg : pkgs)
lift $ Task.throw (Exit.NoSolution badNames)
lift $ Task.throw (Exit.Install (E.NoSolution badNames))
addToPkgHelp :: Name -> Project.PkgInfo -> Solver.Solver (Map Name Constraint)

View File

@ -8,9 +8,7 @@ module Reporting.Exit
where
import qualified Elm.Compiler as Compiler
import qualified Elm.Compiler.Module as Module
import qualified Elm.Package as Pkg
import qualified Json.Encode as Encode
import qualified Reporting.Doc as D
import qualified Reporting.Exit.Assets as Asset
@ -22,6 +20,7 @@ import qualified Reporting.Exit.Diff as Diff
import qualified Reporting.Exit.Help as Help
import qualified Reporting.Exit.Http as Http
import qualified Reporting.Exit.Make as Make
import qualified Reporting.Exit.Install as Install
import qualified Reporting.Exit.Publish as Publish
@ -39,12 +38,10 @@ data Exit
| Deps Deps.Exit
| Diff Diff.Exit
| Make Make.Exit
| Install Install.Exit
| Publish Publish.Exit
| BadHttp String Http.Exit
-- misc
| NoSolution [Pkg.Name]
-- RENDERERS
@ -116,38 +113,11 @@ toReport exit =
Make makeExit ->
Make.toReport makeExit
Install installExit ->
Install.toReport installExit
Publish publishExit ->
Publish.toReport publishExit
BadHttp url httpExit ->
Http.toReport url httpExit
NoSolution badPackages ->
case badPackages of
[] ->
Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
"This usually happens if you try to modify dependency constraints by\
\ hand. I recommend deleting any dependency you added recently (or all\
\ of them if things are bad) and then adding them again with:"
[ D.indent 4 $ D.green "elm install"
, D.reflow $
"And do not be afaid to ask for help on Slack if you get stuck!"
]
_:_ ->
Help.report "OLD DEPENDENCIES" (Just "elm.json")
( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
)
[ D.indent 4 $ D.vcat $ map (D.red . D.fromString . Pkg.toString) badPackages
, D.reflow $
"This may be because it is not upgraded yet. It may be because a\
\ better solution came along, so there was no need to upgrade it.\
\ Etc. Try asking around on Slack to learn more about the topic."
, D.toSimpleNote
"Whatever the case, please be kind to the relevant package authors! Having\
\ friendly interactions with users is great motivation, and conversely, getting\
\ berated by strangers on the internet sucks your soul dry. Furthermore, package\
\ authors are humans with families, friends, jobs, vacations, responsibilities,\
\ goals, etc. They face obstacles outside of their technical work you will never\
\ know about, so please assume the best and try to be patient and supportive!"
]

View File

@ -0,0 +1,82 @@
{-# LANGUAGE OverloadedStrings #-}
module Reporting.Exit.Install
( Exit(..)
, toReport
)
where
import qualified Elm.Compiler as Compiler
import qualified Elm.Package as Pkg
import qualified Reporting.Doc as D
import qualified Reporting.Exit.Help as Help
-- EXITS
data Exit
= NoArgs FilePath
| NoSolution [Pkg.Name]
-- TO REPORT
toReport :: Exit -> Help.Report
toReport exit =
case exit of
NoArgs cacheDir ->
Help.report "INSTALL WHAT?" Nothing
"I am expecting commands like:"
[ D.green $ D.indent 4 $ D.vcat $
[ "elm install elm-lang/http"
, "elm install elm-lang/json"
, "elm install elm-lang/random"
]
, D.toFancyHint
["In","JavaScript","folks","run","`npm install`","to","start","projects."
,"\"Gotta","download","everything!\"","But","why","download","packages"
,"again","and","again?","Instead,","Elm","caches","packages","in"
,D.dullyellow (D.fromString cacheDir)
,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
,"Elm","projects","check","that","cache","before","trying","the","internet."
,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
,"easier","to","work","offline.","As","a","result"
,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
]
]
NoSolution badPackages ->
case badPackages of
[] ->
Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json")
"This usually happens if you try to modify dependency constraints by\
\ hand. I recommend deleting any dependency you added recently (or all\
\ of them if things are bad) and then adding them again with:"
[ D.indent 4 $ D.green "elm install"
, D.reflow $
"And do not be afaid to ask for help on Slack if you get stuck!"
]
_:_ ->
Help.report "OLD DEPENDENCIES" (Just "elm.json")
( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
)
[ D.indent 4 $ D.vcat $ map (D.red . D.fromString . Pkg.toString) badPackages
, D.reflow $
"This may be because it is not upgraded yet. It may be because a\
\ better solution came along, so there was no need to upgrade it.\
\ Etc. Try asking around on Slack to learn more about the topic."
, D.toSimpleNote
"Whatever the case, please be kind to the relevant package authors! Having\
\ friendly interactions with users is great motivation, and conversely, getting\
\ berated by strangers on the internet sucks your soul dry. Furthermore, package\
\ authors are humans with families, friends, jobs, vacations, responsibilities,\
\ goals, etc. They face obstacles outside of their technical work you will never\
\ know about, so please assume the best and try to be patient and supportive!"
]

View File

@ -118,6 +118,7 @@ Executable elm
Reporting.Exit.Help,
Reporting.Exit.Http,
Reporting.Exit.Make,
Reporting.Exit.Install,
Reporting.Exit.Publish,
Reporting.Progress,
Reporting.Progress.Bar,

View File

@ -1,8 +1,14 @@
module Install (run) where
module Install
( Args(..)
, run
)
where
import qualified Elm.Install as Install
import qualified Elm.Package as Pkg
import qualified Reporting.Exit as Exit
import qualified Reporting.Exit.Install as E
import qualified Reporting.Task as Task
import qualified Reporting.Progress.Terminal as Terminal
@ -11,7 +17,19 @@ import qualified Reporting.Progress.Terminal as Terminal
-- RUN
run :: Pkg.Name -> () -> IO ()
run pkg () =
data Args
= NoArgs
| Install Pkg.Name
run :: Args -> () -> IO ()
run args () =
do reporter <- Terminal.create
Task.run reporter $ Install.install pkg
Task.run reporter $
case args of
NoArgs ->
do cacheDir <- Task.getPackageCacheDir
Task.throw (Exit.Install (E.NoArgs cacheDir))
Install pkg ->
Install.install pkg

View File

@ -213,8 +213,14 @@ install =
"What if two projects use different versions of the same package? No problem!\
\ Each project is independent, so there cannot be conflics like that!"
]
installArgs =
oneOf
[ require0 Install.NoArgs
, require1 Install.Install package
]
in
Interface "install" (Common summary) details example (required package) noFlags Install.run
Interface "install" (Common summary) details example installArgs noFlags Install.run