@@ -1,16 +1,22 @@
1−{-# OPTIONS_GHC -Wall #-}
1+{-# LANGUAGE OverloadedStrings #-}
2−module Main where
2+module Main
4−import qualified System.Directory as Dir
5−import System.Exit (exitWith)
6−import qualified System.IO as IO
7−import qualified System.Process as Proc
8import GHC.IO.Encoding (setLocaleEncoding, utf8)
8import GHC.IO.Encoding (setLocaleEncoding, utf8)
9+import qualified Text.PrettyPrint.ANSI.Leijen as P
10+import Text.PrettyPrint.ANSI.Leijen ((<>))
11+import Text.Read (readMaybe)
10import qualified Elm.Compiler as Compiler
13import qualified Elm.Compiler as Compiler
14+import qualified Elm.Diff as Diff
11import qualified Elm.Package as Pkg
15import qualified Elm.Package as Pkg
16+import qualified Generate.Output as Output
18+import Terminal.Args.Helpers
13−import CommandLine.Args as Args
14import qualified Bump
20import qualified Bump
15import qualified Develop
21import qualified Develop
16import qualified Diff
22import qualified Diff
@@ -27,79 +33,189 @@ import qualified Repl
27main :: IO ()
33main :: IO ()
29 do setLocaleEncoding utf8
35 do setLocaleEncoding utf8
51+ ["Hi,","thank","you","for","trying","out","Elm"
52+ ,P.green (P.text (Pkg.versionToString Compiler.version)) <> "."
53+ ,"I hope you like it!"
56+ , P.dullblack "-------------------------------------------------------------------------------"
57+ , P.dullblack "I highly recommend working through <https://guide.elm-lang.org> to get started."
58+ , P.dullblack "It teaches many important concepts, including how to use `elm` in the terminal."
59+ , P.dullblack "-------------------------------------------------------------------------------"
65+ P.fillSep $ map P.text $ words $
66+ "Be sure to ask on the Elm slack if you run into trouble! Folks are friendly and\
67+ \ happy to help out. They hang out there because it is fun, so be kind to get the\
79+ "Open up an interactive programming session. You can type in Elm\
80+ \ expressions and it will tell you what they evaluate to."
83+ Details $ error "TODO"
87+ |-- flag "interpreter" interpreter "Path to a alternate JS interpreter, like node or nodejs."
89+ Interface "repl" (Common summary) details noArgs replFlags Repl.run
92+interpreter :: Parser String
95+ { _singular = "interpreter"
96+ , _plural = "interpreters"
98+ , _suggest = \_ -> return []
99+ , _examples = \_ -> return ["node","nodejs"]
111+ "Easy way to get started with Elm. It shows a file viewer, and when you\
112+ \ click on an Elm file, it compiles it and shows the result."
115+ Details $ error "TODO"
119+ |-- flag "port" port_ "The port of the server (default: 8000)"
121+ Interface "reactor" (Common summary) details noArgs reactorFlags Develop.run
127+ { _singular = "port"
129+ , _parser = readMaybe
130+ , _suggest = \_ -> return []
131+ , _examples = \_ -> return ["3000","8000"]
143+ "Compile files by hand. Once you get comfortable with Elm projects, you\
144+ \ will probably want this level of control during development."
147+ Details $ error "TODO"
151+ |-- onOff "warn" "Report warnings to improve code quality."
152+ |-- onOff "debug" "Generate programs in debug mode."
153+ |-- flag "output" Output.output "Specify the name of the resulting JS file (use --output=/dev/null for no output)"
155+ Interface "make" (Common summary) details (zeroOrMore elmFile) makeFlags Make.run
166+ "Install <https://package.elm-lang.org> packages. Every project is\
167+ \ independent, so you can use different versions in different projects."
170+ Details $ error "TODO"
172+ Interface "install" (Common summary) details (required package) noFlags Install.run
183+ Details $ error "TODO"
185+ Interface "publish" Uncommon details noArgs noFlags Publish.run
196+ Details $ error "TODO"
198+ Interface "bump" Uncommon details noArgs noFlags Bump.run
210+ "The `diff` command detects API changes. Every Elm package has a known public\
211+ \ API, so I can tell you exactly what changed from version to version."
31− route <- Args.chomp
213+ diffArgs =
32− case route of
214+ oneOf
33− Naked () () ->
215+ [ require0 Diff.CodeVsLatest
34− putStrLn $
216+ , require1 Diff.CodeVsExactly version
35− "Elm " ++ Pkg.versionToString Compiler.version
217+ , require2 Diff.LocalInquiry version version
36− ++ " - Get started at <https://guide.elm-lang.org/>!"
218+ , require3 Diff.GlobalInquiry package version version
38− Version () () ->
220+ in
39− putStrLn (Pkg.versionToString Compiler.version)
221+ Interface "diff" Uncommon details diffArgs noFlags Diff.run
63−attemptToRun :: String -> [String] -> IO ()
64−attemptToRun command args =
65− do found <- Dir.findExecutable ("elm-" ++ command)
68− IO.hPutStrLn IO.stderr $
69− "Could not find command `" ++ command ++ "`. Maybe there is a typo?\n\n\
70− \Default commands include:\n\n"
71− ++ availableCommands ++
72− "\nWhen you try to run the command `" ++ command ++ "` we actually search for an\n\
73− \ executable named elm-" ++ command ++ ". Are you able to run elm-" ++ command ++ "?\n\
74− \ Is it on your PATH?"
77− do (_, _, _, handle) <- Proc.createProcess (Proc.proc path args)
78− exitWith =<< Proc.waitForProcess handle
81−usageMessage :: String
83− "Elm Platform " ++ Pkg.versionToString Compiler.version ++ " - a way to run all Elm tools\n\
85− \Usage: elm <command> [<args>]\n\
87− \Available commands include:\n\n"
88− ++ availableCommands ++
89− "\nYou can learn more about a specific command by running things like:\n\
92− \ elm package --help\n\
93− \ elm <command> --help\n\
95− \In all these cases we are simply running 'elm-<command>' so if you create an\n\
96− \executable named 'elm-foobar' you will be able to run it as 'elm foobar' as\n\
97− \long as it appears on your PATH."
100−availableCommands :: String
102− " make Compile an Elm file or project into JS or HTML\n\
103− \ package Manage packages from <http://package.elm-lang.org>\n\
104− \ reactor Develop with compile-on-refresh and time-travel debugging\n\
105− \ repl A REPL for running individual expressions\n"