summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-08-20 22:36:43 +0200
committerEugen Wissner <belka@caraus.de>2024-08-20 22:36:43 +0200
commit14cc805dcfce79ab699ebb83261749a3a1c227fd (patch)
tree34e863241d05cf9fec44b5516e2f78c911d570ae /src/Main.hs
parent42b9b671e1db2ac182ad504b14da9a0f6bb2ff1a (diff)
downloadslackbuilder-14cc805dcfce79ab699ebb83261749a3a1c227fd.tar.gz
Display error descriptions
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ec74432..ba7dc54 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -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