diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-09-08 16:44:57 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-09-08 16:44:57 +0200 |
| commit | 1418e0ae46d3805c20796b0ff7896881658798df (patch) | |
| tree | 238fe3e1044c60ef24c0e756f63723103362aa7c /src | |
| parent | 4f74c2ec10682b4725a413894c67063817810582 (diff) | |
| download | slackbuilder-1418e0ae46d3805c20796b0ff7896881658798df.tar.gz | |
Pretty print settings parsing errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/Main.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Main.hs b/src/Main.hs index ac0b474..375ee8c 100644 --- a/src/Main.hs +++ b/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 - $ runSlackBuilderT - $ executeCommand programCommand +main = execParser slackBuilderParser + >>= handle handleException . withCommandLine where - handleException :: SlackBuilderException -> IO () + withCommandLine programCommand = do + settingsResult <- Toml.decodeFileEither settingsCodec configurationFile + case settingsResult of + Right settings -> flip runReaderT settings + $ runSlackBuilderT + $ executeCommand programCommand + 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) |
