Display error descriptions
All checks were successful
Build / audit (push) Successful in 8s
Build / test (push) Successful in 14m18s

This commit is contained in:
2024-08-20 22:36:43 +02:00
parent 42b9b671e1
commit 14cc805dcf
2 changed files with 47 additions and 8 deletions

View File

@ -6,6 +6,7 @@ module Main
( main
) where
import Control.Exception (Exception(..), handle)
import Data.Char (isNumber)
import Data.List.NonEmpty (NonEmpty(..))
import Control.Monad.Catch (MonadThrow(..))
@ -20,7 +21,6 @@ import SlackBuilder.Update
import qualified Toml
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
import Control.Monad.Trans.Reader (ReaderT(..))
import SlackBuilder.Package (PackageDescription(..))
import qualified SlackBuilder.Package as Package
@ -28,6 +28,13 @@ import Text.URI.QQ (uri)
import Data.Foldable (for_, find)
import GHC.Records (HasField(..))
import System.Process (CmdSpec(..))
import System.Console.ANSI
( setSGR
, SGR(..)
, ColorIntensity(..)
, Color(..)
, ConsoleLayer(..)
)
autoUpdatable :: [PackageDescription]
autoUpdatable =
@ -294,17 +301,20 @@ check = for_ autoUpdatable go
>>= mapM_ checkUpdateAvailability
>> liftIO (putStrLn "")
main :: IO ()
main = do
programCommand <- execParser slackBuilderParser
settings <- Toml.decodeFile settingsCodec "config/config.toml"
latestVersion <- flip runReaderT settings
handle handleException
$ flip runReaderT settings
$ runSlackBuilderT
$ executeCommand programCommand
maybe (pure ()) Text.IO.putStrLn latestVersion
where
handleException :: SlackBuilderException -> IO ()
handleException slackBuilderException
= setSGR [SetColor Foreground Dull Red]
>> putStrLn (displayException slackBuilderException)
>> setSGR [Reset]
executeCommand = \case
CheckCommand -> check >> pure Nothing
Up2DateCommand packageName -> up2Date packageName >> pure Nothing
CheckCommand -> check
Up2DateCommand packageName -> up2Date packageName