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
|
( main
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception (Exception(..), handle)
|
import Control.Exception (Exception(..), handle, SomeException(..))
|
||||||
import Data.Char (isNumber)
|
import Data.Char (isNumber)
|
||||||
import Control.Monad.Catch (MonadThrow(..))
|
import Control.Monad.Catch (MonadThrow(..))
|
||||||
import Control.Monad.IO.Class (MonadIO(..))
|
import Control.Monad.IO.Class (MonadIO(..))
|
||||||
@ -20,6 +20,7 @@ import SlackBuilder.Update
|
|||||||
import qualified Toml
|
import qualified Toml
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
|
import qualified Data.Text.IO as Text
|
||||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
import Control.Monad.Trans.Reader (ReaderT(..))
|
||||||
import SlackBuilder.Package (PackageDescription(..))
|
import SlackBuilder.Package (PackageDescription(..))
|
||||||
import qualified SlackBuilder.Package as Package
|
import qualified SlackBuilder.Package as Package
|
||||||
@ -258,15 +259,22 @@ check = for_ autoUpdatable go
|
|||||||
>> liftIO (putStrLn "")
|
>> liftIO (putStrLn "")
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = execParser slackBuilderParser
|
||||||
programCommand <- execParser slackBuilderParser
|
>>= handle handleException . withCommandLine
|
||||||
settings <- Toml.decodeFile settingsCodec "config/config.toml"
|
where
|
||||||
handle handleException
|
withCommandLine programCommand = do
|
||||||
$ flip runReaderT settings
|
settingsResult <- Toml.decodeFileEither settingsCodec configurationFile
|
||||||
|
case settingsResult of
|
||||||
|
Right settings -> flip runReaderT settings
|
||||||
$ runSlackBuilderT
|
$ runSlackBuilderT
|
||||||
$ executeCommand programCommand
|
$ executeCommand programCommand
|
||||||
where
|
Left settingsErrors
|
||||||
handleException :: SlackBuilderException -> IO ()
|
-> 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
|
handleException slackBuilderException
|
||||||
= setSGR [SetColor Foreground Dull Red]
|
= setSGR [SetColor Foreground Dull Red]
|
||||||
>> putStrLn (displayException slackBuilderException)
|
>> putStrLn (displayException slackBuilderException)
|
||||||
|
Loading…
Reference in New Issue
Block a user