From d9af0dce764d8cbc01053ed41e87047b63694a24 Mon Sep 17 00:00:00 2001 From: 50^2 <36756030+aleeusgr@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:13:02 +0200 Subject: [PATCH] Fix #9151 (cabal init logs at loglevel "Log") (#9346) * rm Log from Severity loglevels * replace Log with Info * add changelog * fix typo * fix changelog entry * add displaySeverity * fix changelog * run fourmolu * implement case expression in displaySeverity --- .../src/Distribution/Client/Init/FileCreators.hs | 10 +++++----- cabal-install/src/Distribution/Client/Init/Types.hs | 12 +++++++++--- cabal-install/src/Distribution/Client/Init/Utils.hs | 2 +- changelog.d/pr-9346 | 12 ++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 changelog.d/pr-9346 diff --git a/cabal-install/src/Distribution/Client/Init/FileCreators.hs b/cabal-install/src/Distribution/Client/Init/FileCreators.hs index 18ea0bc71a1..f53ce7a6e53 100644 --- a/cabal-install/src/Distribution/Client/Init/FileCreators.hs +++ b/cabal-install/src/Distribution/Client/Init/FileCreators.hs @@ -65,7 +65,7 @@ writeProject (ProjectSettings opts pkgDesc libTarget exeTarget testTarget) message opts T.Error "no package name given, so no .cabal file can be generated\n" | otherwise = do -- clear prompt history a bit" - message opts T.Log $ + message opts T.Info $ "Using cabal specification: " ++ showCabalSpecVersion (_optCabalSpec opts) @@ -269,7 +269,7 @@ writeFileSafe opts fileName content = do go exists - message opts T.Log $ show action ++ " file " ++ fileName ++ "..." + message opts T.Info $ show action ++ " file " ++ fileName ++ "..." return $ action == Existing where doOverwrite = _optOverwrite opts @@ -279,7 +279,7 @@ writeFileSafe opts fileName content = do writeFile fileName content | exists && doOverwrite = do newName <- findNewPath fileName - message opts T.Log $ + message opts T.Info $ concat [ fileName , " already exists. Backing up old version in " @@ -302,7 +302,7 @@ writeDirectoriesSafe opts dirs = fmap or $ for dirs $ \dir -> do go dir exists - message opts T.Log $ show action ++ " directory ./" ++ dir ++ "..." + message opts T.Info $ show action ++ " directory ./" ++ dir ++ "..." return $ action == Existing where doOverwrite = _optOverwrite opts @@ -312,7 +312,7 @@ writeDirectoriesSafe opts dirs = fmap or $ for dirs $ \dir -> do createDirectory dir | exists && doOverwrite = do newDir <- findNewPath dir - message opts T.Log $ + message opts T.Info $ concat [ dir , " already exists. Backing up old version in " diff --git a/cabal-install/src/Distribution/Client/Init/Types.hs b/cabal-install/src/Distribution/Client/Init/Types.hs index 41513d0f048..ee7d7cbe0c3 100644 --- a/cabal-install/src/Distribution/Client/Init/Types.hs +++ b/cabal-install/src/Distribution/Client/Init/Types.hs @@ -368,7 +368,7 @@ instance Interactive IO where hFlush = System.IO.hFlush message q severity msg | q == silent = pure () - | otherwise = putStrLn $ "[" ++ show severity ++ "] " ++ msg + | otherwise = putStrLn $ "[" ++ displaySeverity severity ++ "] " ++ msg break = return False throwPrompt = throwM @@ -407,7 +407,7 @@ instance Interactive PurePrompt where Error -> PurePrompt $ \_ -> Left $ BreakException - (show severity ++ ": " ++ msg) + (displaySeverity severity ++ ": " ++ msg) _ -> return () break = return True @@ -455,7 +455,13 @@ newtype BreakException = BreakException String deriving (Eq, Show) instance Exception BreakException -- | Used to inform the intent of prompted messages. -data Severity = Log | Info | Warning | Error deriving (Eq, Show) +data Severity = Info | Warning | Error deriving (Eq) + +displaySeverity :: Severity -> String +displaySeverity severity = case severity of + Info -> "Info" + Warning -> "Warn" + Error -> "Err" -- | Convenience alias for the literate haskell flag type IsLiterate = Bool diff --git a/cabal-install/src/Distribution/Client/Init/Utils.hs b/cabal-install/src/Distribution/Client/Init/Utils.hs index e8cde1184ae..f986cce0e03 100644 --- a/cabal-install/src/Distribution/Client/Init/Utils.hs +++ b/cabal-install/src/Distribution/Client/Init/Utils.hs @@ -214,7 +214,7 @@ retrieveDependencies v flags mods' pkgIx = do modDeps = map (\(mn, ds) -> (mn, ds, M.lookup ds modMap)) mods -- modDeps = map (id &&& flip M.lookup modMap) mods - message v Log "Guessing dependencies..." + message v Info "Guessing dependencies..." nub . catMaybes <$> traverse (chooseDep v flags) modDeps -- Given a module and a list of installed packages providing it, diff --git a/changelog.d/pr-9346 b/changelog.d/pr-9346 new file mode 100644 index 00000000000..3f31da43837 --- /dev/null +++ b/changelog.d/pr-9346 @@ -0,0 +1,12 @@ +synopsis: remove +packages: cabal-install +prs: #9346 +issues: #9151 +significance: significant + +description: { + +- Remove "Log" as a log level in favour of "Info". +- Remove "Show" in Severity and replace by "displaySeverity" function + +}