@@ -0,0 +1,73 @@
1+module Main where
2+
3+import qualified System.Directory as Dir
4+import qualified System.Environment as Env
5+import System.Exit (exitWith)
6+import System.IO (hPutStrLn, stderr, stdin, stdout)
7+import qualified System.Process as Proc
8+
9+import qualified Elm.Compiler.Version as Compiler
10+
11+
12+main :: IO ()
13+main =
14+ do allArgs <- Env.getArgs
15+ case allArgs of
16+ [] ->
17+ putStrLn usageMessage
18+
19+ command : args ->
20+ attemptToRun command args
21+
22+
23+attemptToRun :: String -> [String] -> IO ()
24+attemptToRun command args =
25+ do found <- Dir.findExecutable ("elm-" ++ command)
26+ case found of
27+ Nothing ->
28+ hPutStrLn stderr $
29+ "Could not find command '" ++ command ++ "'. Maybe there is a typo?\n\n\
30+ \Default commands include:\n\n"
31+ ++ availableCommands ++
32+ "\nWhen you try to run the command '" ++ command ++ "' we actually search for an\n\
33+ \ executable named elm-" ++ command ++ ". Are you able to run elm-" ++ command ++ "?\n\
34+ \ Is it on your PATH?"
35+
36+ Just path ->
37+ let createProc =
38+ (Proc.proc path args)
39+ { Proc.std_in = Proc.UseHandle stdin
40+ , Proc.std_out = Proc.UseHandle stdout
41+ , Proc.std_err = Proc.UseHandle stderr
42+ }
43+ in
44+ do (_, _, _, handle) <- Proc.createProcess createProc
45+ exitWith =<< Proc.waitForProcess handle
46+
47+
48+usageMessage :: String
49+usageMessage =
50+ "Elm Platform " ++ Compiler.version ++ " - a way to run all Elm tools\n\
51+ \\n\
52+ \Usage: elm <command> [<args>]\n\
53+ \\n\
54+ \Available commands include:\n\n"
55+ ++ availableCommands ++
56+ "\nYou can learn more about a specific command by running things like:\n\
57+ \\n\
58+ \ elm make --help\n\
59+ \ elm package --help\n\
60+ \ elm <command> --help\n\
61+ \\n\
62+ \In all these cases we are simply running 'elm-<command>' so if you create an\n\
63+ \executable named 'elm-foobar' you will be able to run it as 'elm foobar' as\n\
64+ \long as it appears on your PATH."
65+
66+
67+availableCommands :: String
68+availableCommands =
69+ " make Compile an Elm file or project into JS or HTML\n\
70+ \ package Manage packages from <http://package.elm-lang.org>\n\
71+ \ reactor Develop with compile-on-refresh and time-travel debugging\n\
72+ \ repl A REPL for running individual expressions\n"
73+