Skip to content

Commit

Permalink
Success
Browse files Browse the repository at this point in the history
  • Loading branch information
nalchevanidze committed Sep 1, 2024
1 parent 3ba26da commit 641d312
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions hconf/src/HConf/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module HConf.Format (format) where
import qualified Data.Text.IO.Utf8 as T
import HConf.Core.PkgDir (explore)
import HConf.Utils.Class (HConfIO)
import HConf.Utils.Core (throwError)
import HConf.Utils.Core (throwError, isSuccess)
import HConf.Utils.FromConf (ReadConf, readList)
import HConf.Utils.Log (task)
import Ormolu
Expand Down Expand Up @@ -52,6 +52,3 @@ formatter path =
handleDiff :: Maybe TextDiff -> IO ExitCode
handleDiff = maybe (pure ExitSuccess) (\diff -> runTerm (printTextDiff diff) Always stderr $> ExitFailure 100)

isSuccess :: ExitCode -> Bool
isSuccess ExitSuccess = True
isSuccess ExitFailure {} = False
12 changes: 6 additions & 6 deletions hconf/src/HConf/Utils/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module HConf.Utils.Core
DependencyName (..),
select,
PkgName (..),
isSuccess,
)
where

Expand Down Expand Up @@ -224,12 +225,7 @@ select e k = maybeToError ("Unknown " <> e <> ": " <> msg k <> "!") . lookup k
exec :: (MonadIO m) => FilePath -> [String] -> m (String, Bool)
exec name options = do
(code, _, out) <- liftIO (readProcessWithExitCode name options "")
pure
( out,
case code of
ExitSuccess {} -> True
ExitFailure {} -> False
)
pure (out, isSuccess code)

printException :: SomeException -> String
printException = show
Expand All @@ -241,3 +237,7 @@ safeIO = tryJust (Just . printException)

withThrow :: (MonadFail m) => m (Result a) -> m a
withThrow x = x >>= either (throwError . msg) pure

isSuccess :: ExitCode -> Bool
isSuccess ExitSuccess = True
isSuccess ExitFailure {} = False

0 comments on commit 641d312

Please sign in to comment.