From dfe213824fc6b0dce5ed3cd0d436d8001165b41d Mon Sep 17 00:00:00 2001 From: "Rune K. Svendsen" Date: Sat, 30 Dec 2023 14:13:16 +0100 Subject: [PATCH 1/2] Improve NoDownload Pretty instance on missing/unknown "mtarget" The guard was only used for the "Perhaps you meant"-part, so include the other part regardless of what `mtarget` is. --- lib/GHCup/Errors.hs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/GHCup/Errors.hs b/lib/GHCup/Errors.hs index 7cac935..c3fd888 100644 --- a/lib/GHCup/Errors.hs +++ b/lib/GHCup/Errors.hs @@ -212,20 +212,22 @@ data NoDownload = NoDownload GHCTargetVersion Tool (Maybe PlatformRequest) deriving Show instance Pretty NoDownload where - pPrint (NoDownload tver@(GHCTargetVersion mtarget vv) tool mpfreq) - | (Just target) <- mtarget - , target `elem` (T.pack . prettyShow <$> enumFromTo (minBound :: Tool) (maxBound :: Tool)) - = text $ "Unable to find a download for " + pPrint (NoDownload tver@(GHCTargetVersion mtarget vv) tool mpfreq) = + let helperMsg + | (Just target) <- mtarget + , target `elem` (T.pack . prettyShow <$> enumFromTo (minBound :: Tool) (maxBound :: Tool)) = + "\nPerhaps you meant: 'ghcup " + <> T.unpack target + <> " " + <> T.unpack (prettyVer vv) + <> "'" + | otherwise = "" + in text $ "Unable to find a download for " <> show tool - <> " version '" - <> T.unpack (tVerToText tver) - <> maybe "'\n" (\pfreq -> "' on detected platform " <> pfReqToString pfreq <> "\n") mpfreq - <> "Perhaps you meant: 'ghcup " - <> T.unpack target - <> " " - <> T.unpack (prettyVer vv) - <> "'" - | otherwise = text $ "Unable to find a download for " <> T.unpack (tVerToText tver) + <> " version " + <> "'" <> T.unpack (tVerToText tver) <> "'" + <> maybe "" (\pfreq -> " on detected platform " <> pfReqToString pfreq) mpfreq + <> helperMsg instance HFErrorProject NoDownload where eBase _ = 10 From 6fec9d473796533c20be592726d10106261a6672 Mon Sep 17 00:00:00 2001 From: "Rune K. Svendsen" Date: Thu, 11 Jan 2024 11:42:56 +0100 Subject: [PATCH 2/2] Quote version in `Pretty NotInstalled` instance --- lib/GHCup/Errors.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/GHCup/Errors.hs b/lib/GHCup/Errors.hs index c3fd888..84fe860 100644 --- a/lib/GHCup/Errors.hs +++ b/lib/GHCup/Errors.hs @@ -389,7 +389,7 @@ data NotInstalled = NotInstalled Tool GHCTargetVersion instance Pretty NotInstalled where pPrint (NotInstalled tool ver) = - text "The version" <+> pPrint ver <+> text "of the tool" <+> pPrint tool <+> text "is not installed." + text "The version" <+> (text "'" <> pPrint ver <> text "'") <+> text "of the tool" <+> pPrint tool <+> text "is not installed." instance HFErrorProject NotInstalled where eBase _ = 130