on 8f7c3cd help sign in
elk/cli/src/Main.hs
105 lines 2.9 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module Main where
4import qualified System.Directory as Dir
5import System.Exit (exitWith)
6import qualified System.IO as IO
7import qualified System.Process as Proc
8import GHC.IO.Encoding (setLocaleEncoding, utf8)
10import qualified Elm.Compiler as Compiler
11import qualified Elm.Package as Pkg
13import CommandLine.Args as Args
14import qualified Bump
15import qualified Develop
16import qualified Diff
17import qualified Install
18import qualified Make
19import qualified Publish
20import qualified Repl
24-- MAIN
27main :: IO ()
28main =
29 do setLocaleEncoding utf8
31 route <- Args.chomp
32 case route of
33 Naked () () ->
34 putStrLn $
35 "Elm " ++ Pkg.versionToString Compiler.version
36 ++ " - Get started at <https://guide.elm-lang.org/>!"
38 Version () () ->
39 putStrLn (Pkg.versionToString Compiler.version)
41 Install pkg () ->
42 Install.run pkg
44 Publish () () ->
45 Publish.run
47 Make paths flags ->
48 Make.run paths flags
50 Bump () () ->
51 Bump.run
53 Diff args () ->
54 Diff.run args
56 Repl () flags ->
57 Repl.run flags
59 Dev () flags ->
60 Develop.run flags
63attemptToRun :: String -> [String] -> IO ()
64attemptToRun command args =
65 do found <- Dir.findExecutable ("elm-" ++ command)
66 case found of
67 Nothing ->
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?"
76 Just path ->
77 do (_, _, _, handle) <- Proc.createProcess (Proc.proc path args)
78 exitWith =<< Proc.waitForProcess handle
81usageMessage :: String
82usageMessage =
83 "Elm Platform " ++ Pkg.versionToString Compiler.version ++ " - a way to run all Elm tools\n\
84 \\n\
85 \Usage: elm <command> [<args>]\n\
86 \\n\
87 \Available commands include:\n\n"
88 ++ availableCommands ++
89 "\nYou can learn more about a specific command by running things like:\n\
90 \\n\
91 \ elm make --help\n\
92 \ elm package --help\n\
93 \ elm <command> --help\n\
94 \\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."
100availableCommands :: String
101availableCommands =
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"