on master help sign in
Get rid of Elm.Utils.run
6aa54d5Evan Czaplicki
src/Elm/Utils.hs+6−62
@@ -1,10 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE OverloadedStrings #-}
4module Elm.Utils
2module Elm.Utils
5 ( (|>), (<|)
3 ( (|>), (<|)
6− , run, unwrappedRun
4+ , nearbyNames
7− , CommandError(..)
8 , isDeclaration
5 , isDeclaration
9 ) where
6 ) where
10
7
@@ -18,6 +15,11 @@ import qualified AST.Pattern as Pattern
18import qualified Parse.Helpers as Parse
15import qualified Parse.Helpers as Parse
19import qualified Parse.Expression as Parse
16import qualified Parse.Expression as Parse
20import qualified Reporting.Annotation as A
17import qualified Reporting.Annotation as A
18+import Reporting.Helpers (nearbyNames)
19+
20+
21+
22+-- PIPES
21
23
22
24
23{-| Forward function application `x |> f == f x`. This function is useful
25{-| Forward function application `x |> f == f x`. This function is useful
@@ -38,64 +40,6 @@ infixr 0 <|
38infixl 0 |>
40infixl 0 |>
39
41
40
42
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−
99
43
100-- DECL CHECKER
44-- DECL CHECKER
101
45