Pretty print settings parsing errors
This commit is contained in:
parent
4f74c2ec10
commit
1418e0ae46
24
src/Main.hs
24
src/Main.hs
@ -6,7 +6,7 @@ module Main
|
||||
( main
|
||||
) where
|
||||
|
||||
import Control.Exception (Exception(..), handle)
|
||||
import Control.Exception (Exception(..), handle, SomeException(..))
|
||||
import Data.Char (isNumber)
|
||||
import Control.Monad.Catch (MonadThrow(..))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
@ -20,6 +20,7 @@ import SlackBuilder.Update
|
||||
import qualified Toml
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text
|
||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
||||
import SlackBuilder.Package (PackageDescription(..))
|
||||
import qualified SlackBuilder.Package as Package
|
||||
@ -258,15 +259,22 @@ check = for_ autoUpdatable go
|
||||
>> liftIO (putStrLn "")
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
programCommand <- execParser slackBuilderParser
|
||||
settings <- Toml.decodeFile settingsCodec "config/config.toml"
|
||||
handle handleException
|
||||
$ flip runReaderT settings
|
||||
main = execParser slackBuilderParser
|
||||
>>= handle handleException . withCommandLine
|
||||
where
|
||||
withCommandLine programCommand = do
|
||||
settingsResult <- Toml.decodeFileEither settingsCodec configurationFile
|
||||
case settingsResult of
|
||||
Right settings -> flip runReaderT settings
|
||||
$ runSlackBuilderT
|
||||
$ executeCommand programCommand
|
||||
where
|
||||
handleException :: SlackBuilderException -> IO ()
|
||||
Left settingsErrors
|
||||
-> setSGR [SetColor Foreground Dull Red]
|
||||
>> putStrLn (configurationFile <> " parsing failed.")
|
||||
>> setSGR [Reset]
|
||||
>> Text.putStr (Toml.prettyTomlDecodeErrors settingsErrors)
|
||||
configurationFile = "config/config.toml"
|
||||
handleException :: SomeException -> IO ()
|
||||
handleException slackBuilderException
|
||||
= setSGR [SetColor Foreground Dull Red]
|
||||
>> putStrLn (displayException slackBuilderException)
|
||||
|
Loading…
Reference in New Issue
Block a user