From 82dbbc0eed18c86aae1a8f1f92a0c98684e63409 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 26 Jan 2021 19:05:58 -0500 Subject: Create Biz.Log library, extracted from Biz.Bild --- Biz/Lint.hs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'Biz/Lint.hs') diff --git a/Biz/Lint.hs b/Biz/Lint.hs index ccbb393..26d4e6d 100644 --- a/Biz/Lint.hs +++ b/Biz/Lint.hs @@ -11,6 +11,7 @@ module Biz.Lint (main) where import Alpha import qualified Biz.Cli as Cli +import qualified Biz.Log as Log import Biz.Namespace (Ext (..), Namespace (..)) import qualified Biz.Namespace as Namespace import Biz.Test ((@=?)) @@ -18,7 +19,6 @@ import qualified Biz.Test as Test import qualified Control.Concurrent.Async as Async import qualified Data.String as String import qualified Data.Text as Text -import Rainbow (chunk, fore, green, putChunkLn, red, yellow) import qualified System.Directory as Directory import qualified System.Environment as Environment import qualified System.Exit as Exit @@ -34,7 +34,13 @@ move args = case Cli.getAllArgs args (Cli.argument "file") of files -> run (filter notcab files) >>= mapM printResult >>= exit test :: Test.Tree -test = Test.group "Biz.Lint" [Test.unit "id" <| 1 @=? 1] +test = + Test.group + "Biz.Lint" + [ Test.unit "haskell files return two Results" <| do + results <- run ["Biz/Lint.hs"] + length results @=? 2 + ] notcab :: FilePath -> Bool notcab ('_' : _) = False @@ -59,27 +65,19 @@ exit results = Exit.exitWith <| if n > 0 then Exit.ExitFailure n else Exit.ExitS bad Ok {status = Bad _} = True bad _ = False -schunk = chunk <. Text.pack - printResult :: Result -> IO Result -printResult r@(Warn err) = - (putChunkLn <| fore yellow <| "lint: warn: " <> chunk err) >> pure r +printResult r@(Warn err) = Log.warn ["lint", err] >> Log.br >> pure r printResult r@(Ok path_ linter_ (Bad err)) = - ( putChunkLn <| fore red <| "lint: baad: " - <> schunk linter_ - <> ": " - <> schunk path_ - ) + Log.fail ["lint", linter_, Text.pack path_] + >> Log.br >> if err == "" then pure r else putText (Text.pack err) >> pure r printResult r@(Ok path_ linter_ Good) = - ( putChunkLn <| fore green <| "lint: good: " - <> schunk linter_ - <> ": " - <> schunk path_ - ) + Log.good ["lint", linter_, Text.pack path_] + >> Log.br >> pure r printResult r@(NoOp path_) = - (putText <| "lint: noop: " <> Text.pack path_) + Log.info ["lint", "noop", Text.pack path_] + >> Log.br >> pure r changedFiles :: IO [FilePath] @@ -91,7 +89,7 @@ changedFiles = mergeBase >>= changed String.lines [String] -> FilePath -> IO Result lint bin args path_ = - Process.readProcessWithExitCode bin (args ++ [path_]) "" >>= \case + Process.readProcessWithExitCode (Text.unpack bin) (args ++ [path_]) "" >>= \case (Exit.ExitSuccess, _, _) -> pure <| Ok path_ bin Good (Exit.ExitFailure _, msg, _) -> pure <| Ok path_ bin <| Bad msg -- cgit v1.2.3