From 641d3122b5aedad5826bdb750633fda9db167694 Mon Sep 17 00:00:00 2001 From: David Nalchevanidze Date: Sun, 1 Sep 2024 15:27:40 +0200 Subject: [PATCH] Success --- hconf/src/HConf/Format.hs | 5 +---- hconf/src/HConf/Utils/Core.hs | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/hconf/src/HConf/Format.hs b/hconf/src/HConf/Format.hs index 775eae1..6ff9781 100644 --- a/hconf/src/HConf/Format.hs +++ b/hconf/src/HConf/Format.hs @@ -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 @@ -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 diff --git a/hconf/src/HConf/Utils/Core.hs b/hconf/src/HConf/Utils/Core.hs index c0ca89d..146a8a6 100644 --- a/hconf/src/HConf/Utils/Core.hs +++ b/hconf/src/HConf/Utils/Core.hs @@ -32,6 +32,7 @@ module HConf.Utils.Core DependencyName (..), select, PkgName (..), + isSuccess, ) where @@ -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 @@ -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 \ No newline at end of file