Skip to content

Commit

Permalink
class
Browse files Browse the repository at this point in the history
  • Loading branch information
nalchevanidze committed Jul 17, 2024
1 parent a5daa5d commit f857219
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions hconf/src/HConf/Stack/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ where
import Data.Text (pack, unpack)
import HConf.Core.PkgDir (PkgDir, cabalFile)
import HConf.Core.Version (Version)
import HConf.Utils.Class (Check (..), FLog (..), HConfIO (..), Parse (..), withThrow)
import HConf.Utils.Class (Check (..), HConfIO (..), Log (..), Parse (..), withThrow)
import HConf.Utils.Core (Msg (..), Name, exec, select, throwError)
import HConf.Utils.Log (alert, field, task, warn)
import HConf.Utils.Source (fromByteString, ignoreEmpty, indentText, isIndentedLine, parseField, parseLines, startsLike)
Expand Down Expand Up @@ -56,12 +56,12 @@ stack cmd pkg options = do
else alert $ cmd <> ": " <> unpack (indentText $ pack out)
)

instance FLog Warning where
flog (Warning x ls) = warn (unpack x) >> traverse_ (warn . unpack) ls
instance Log Warning where
log (Warning x ls) = warn (unpack x) >> traverse_ (warn . unpack) ls

printWarnings :: (HConfIO m) => Name -> [Warning] -> m ()
printWarnings cmd [] = field cmd "ok"
printWarnings cmd xs = task cmd $ traverse_ flog xs
printWarnings cmd xs = task cmd $ traverse_ log xs

parseWarnings :: String -> [Warning]
parseWarnings = mapMaybe toWarning . groupTopics . parseLines . pack
Expand All @@ -83,8 +83,8 @@ data CabalSrc = CabalSrc
target :: Cabal
}

instance FLog Cabal where
flog Cabal {..} = field name (show version)
instance Log Cabal where
log Cabal {..} = field name (show version)

instance (HConfIO m) => Check m CabalSrc where
check CabalSrc {..} = task "cabal" $ do
Expand All @@ -94,5 +94,5 @@ instance (HConfIO m) => Check m CabalSrc where
stack "sdist" pkgDir []
cabal <- getCabal path
if cabal == target
then flog cabal
then log cabal
else throwError $ "mismatching version or name" <> msg pkgDir
10 changes: 5 additions & 5 deletions hconf/src/HConf/Utils/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module HConf.Utils.Class
HConfIO (..),
LookupConf (..),
ResultT,
FLog (..),
Log (..),
withThrow,
Format (..),
Diff (..),
Expand All @@ -38,11 +38,11 @@ import Relude hiding (readFile, writeFile)
import System.Directory (removeFile)
import System.IO.Error (isDoesNotExistError)

class FLog a where
flog :: (HConfIO m) => a -> m ()
class Log a where
log :: (HConfIO m) => a -> m ()

instance (FLog a) => FLog [a] where
flog = traverse_ flog
instance (Log a) => Log [a] where
log = traverse_ log

class Parse a where
parse :: (MonadFail m) => Text -> m a
Expand Down

0 comments on commit f857219

Please sign in to comment.