on master help sign in
Move the "elm" executable into this repo
77961c3Evan Czaplicki
elm-compiler.cabal+34
@@ -183,6 +183,40 @@ Executable elm-doc
183 union-find >= 0.2 && < 0.3
183 union-find >= 0.2 && < 0.3
184
184
185
185
186+Executable elm
187+ ghc-options:
188+ -threaded -O2 -W
189+
190+ Hs-Source-Dirs:
191+ src
192+
193+ Main-is:
194+ CommandLineRouter.hs
195+
196+ other-modules:
197+ Elm.Compiler.Version
198+
199+ Build-depends:
200+ aeson >= 0.7 && < 0.9,
201+ aeson-pretty >= 0.7 && < 0.8,
202+ base >=4.2 && <5,
203+ binary >= 0.7.0.0 && < 0.8,
204+ bytestring >= 0.9 && < 0.11,
205+ cmdargs >= 0.7 && < 0.11,
206+ containers >= 0.3 && < 0.6,
207+ directory >= 1.0 && < 2.0,
208+ filepath >= 1 && < 2.0,
209+ indents >= 0.3 && < 0.4,
210+ language-glsl >= 0.0.2 && < 0.2,
211+ mtl >= 2 && < 3,
212+ parsec >= 3.1.1 && < 3.5,
213+ pretty >= 1.0 && < 2.0,
214+ process,
215+ text >= 1 && < 2,
216+ transformers >= 0.2 && < 0.5,
217+ union-find >= 0.2 && < 0.3
218+
219+
186Test-Suite compiler-tests
220Test-Suite compiler-tests
187 Type:
221 Type:
188 exitcode-stdio-1.0
222 exitcode-stdio-1.0
src/CommandLineRouter.hsnew file+73
@@ -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+