module Trace.Hpc.Codecov.Main (defaultMain) where
import Control.Exception (Exception (..), handle, throwIO)
import System.Environment (getArgs, getProgName)
import System.Exit (exitFailure)
import Trace.Hpc.Codecov.Exception
import Trace.Hpc.Codecov.Options
import Trace.Hpc.Codecov.Report
defaultMain :: IO ()
defaultMain :: IO ()
defaultMain = (HpcCodecovError -> IO ()) -> IO () -> IO ()
forall e a. Exception e => (e -> IO a) -> IO a -> IO a
handle HpcCodecovError -> IO ()
forall a. HpcCodecovError -> IO a
handler (IO [String]
getArgs IO [String] -> ([String] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [String] -> IO ()
go)
where
go :: [String] -> IO ()
go [String]
args =
case [String] -> Either [String] Options
parseOptions [String]
args of
Right Options
opts | Options -> Bool
optShowHelp Options
opts -> IO ()
printHelp
| Options -> Bool
optShowVersion Options
opts -> IO ()
printVersion
| Options -> Bool
optShowNumeric Options
opts -> IO ()
printNumericVersion
| Bool
otherwise -> Options -> IO Report
opt2rpt Options
opts IO Report -> (Report -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Report -> IO ()
genReport
Left [String]
errs -> HpcCodecovError -> IO ()
forall e a. Exception e => e -> IO a
throwIO ([String] -> HpcCodecovError
InvalidArgs [String]
errs)
handler :: HpcCodecovError -> IO a
handler :: forall a. HpcCodecovError -> IO a
handler HpcCodecovError
e =
do String -> IO ()
putStr (String
"Error: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ HpcCodecovError -> String
forall e. Exception e => e -> String
displayException HpcCodecovError
e)
String
name <- IO String
getProgName
String -> IO ()
putStrLn (String
"Run '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" --help' for usage.")
IO a
forall a. IO a
exitFailure