blob: 2aa1e05a0aeb38636d6160ef4a87453e5abc8d2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
module Bustle.Noninteractive (run)
where
import Prelude hiding (log)
import System
import System.IO (hPutStrLn, stderr)
import Bustle.Parser (readLog)
import Bustle.Types
warn :: String -> IO ()
warn = hPutStrLn stderr
process :: FilePath -> (Log -> [a]) -> (a -> String) -> IO ()
process filepath analyze format = do
input <- readFile filepath
case readLog input of
Left err -> do warn $ concat [ "Couldn't parse "
, filepath
, ": "
, show err
]
exitFailure
Right log -> mapM_ (putStrLn . format) $ analyze log
run :: String -> (Log -> [a]) -> (a -> String) -> IO ()
run appName analyze format = do
args <- getArgs
case args of
[filepath] -> process filepath analyze format
_ -> do hPutStrLn stderr $ concat [ "Usage: "
, appName
, " foo.bustle"
]
exitFailure
|