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