on master help sign in
Get rid of Elm.Utils.run

This was primarily for calling elm-make and elm-package from each other. In the new architecture, this will not have to go through system calls anymore.

commit6aa54d5abed60f7bca2fb35d8f926864fb6d8216 authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 17 Mar 2017, 17:00 (10 years ago) parent7bb1738
1 file changed+6−62
src/Elm/Utils.hs+6−62
src/Elm/Utils.hs+6−62
@@ -1,10 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE OverloadedStrings #-}
42module Elm.Utils
53 ( (|>), (<|)
6− , run, unwrappedRun
7− , CommandError(..)
4+ , nearbyNames
85 , isDeclaration
96 ) where
107
@@ -18,6 +15,11 @@ import qualified AST.Pattern as Pattern
1815import qualified Parse.Helpers as Parse
1916import qualified Parse.Expression as Parse
2017import qualified Reporting.Annotation as A
18+import Reporting.Helpers (nearbyNames)
19+
20+
21+
22+-- PIPES
2123
2224
2325{-| Forward function application `x |> f == f x`. This function is useful
@@ -38,64 +40,6 @@ infixr 0 <|
3840infixl 0 |>
3941
4042
41−-- RUN EXECUTABLES
42−
43−data CommandError
44− = MissingExe String
45− | CommandFailed String String
46−
47−
48−{-| Run a command, throw an error if the command is not found or if something
49−goes wrong.
50−-}
51−run :: (MonadError String m, MonadIO m) => String -> [String] -> m String
52−run command args =
53− do result <- liftIO (unwrappedRun command args)
54− case result of
55− Right out ->
56− return out
57−
58− Left err ->
59− throwError (context (message err))
60− where
61− context msg =
62− "failure when running:" ++ concatMap (' ':) (command:args) ++ "\n" ++ msg
63−
64− message err =
65− case err of
66− CommandFailed stdout stderr ->
67− stdout ++ stderr
68−
69− MissingExe msg ->
70− msg
71−
72−
73−unwrappedRun :: String -> [String] -> IO (Either CommandError String)
74−unwrappedRun command args =
75− do (exitCode, stdout, stderr) <- readProcessWithExitCode command args ""
76− return $
77− case exitCode of
78− ExitSuccess ->
79− Right stdout
80−
81− ExitFailure code ->
82− if code == 127 then
83− Left (missingExe command) -- UNIX
84−
85− else if code == 9009 then
86− Left (missingExe command) -- Windows
87−
88− else
89− Left (CommandFailed stdout stderr)
90−
91−
92−missingExe :: String -> CommandError
93−missingExe command =
94− MissingExe $
95− "Could not find command `" ++ command ++ "`. Do you have it installed?\n\
96− \ Can it be run from anywhere? Is it on your PATH?"
97−
98−
9943
10044-- DECL CHECKER
10145