~jojo/Carth

ref: b357627c90810c29b93cd9823eb9831051b30eaa Carth/src/Conf.hs -rw-r--r-- 896 bytes
b357627cJoJo Add `--verbose` flag. Don't print stuff when off. 1 year, 8 months ago
                                                                                
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
37
38
39
40
41
42
module Conf
    ( Conf(..)
    , CompileConfig(..)
    , RunConfig(..)
    , verbose
    , Config(..)
    )
where

import Control.Monad

data Conf
    = CompileConf CompileConfig
    | RunConf RunConfig

data CompileConfig = CompileConfig
    { cInfile :: FilePath
    , cOutfile :: FilePath
    -- | Path to C compiler to use for linking and compiling ".c" files
    , cCompiler :: FilePath
    , cDebug :: Bool
    , cVerbose :: Bool
    }

data RunConfig = RunConfig
    { rInfile :: FilePath
    , rDebug :: Bool
    , rVerbose :: Bool
    }

class Config cfg where
    getDebug :: cfg -> Bool
    getVerbose :: cfg -> Bool
instance Config CompileConfig where
    getDebug = cDebug
    getVerbose = cVerbose
instance Config RunConfig where
    getDebug = rDebug
    getVerbose = rVerbose

verbose :: Config cfg => cfg -> String -> IO ()
verbose cfg msg = when (getVerbose cfg) $ putStrLn msg