on 3f9cbab help sign in
elk/src/CommandLineRouter.hs
73 lines 2.4 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
9import qualified Elm.Compiler.Version as Compiler
10import qualified Elm.Package as Pkg
12main :: IO ()
13main =
14 do allArgs <- Env.getArgs
15 case allArgs of
16 [] ->
17 putStrLn usageMessage
19 command : args ->
20 attemptToRun command args
23attemptToRun :: String -> [String] -> IO ()
24attemptToRun 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?"
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
48usageMessage :: String
49usageMessage =
50 "Elm Platform " ++ (Pkg.versionToString 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."
67availableCommands :: String
68availableCommands =
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"