Commit 12c1cfb7 authored by Keshav Kini's avatar Keshav Kini
Browse files

Better message when new cabal-install available

A common mistake new users of cabal-install seem to make is to run
`cabal update`, see the message "Note: there is a new version of
cabal-install available.", accordingly install a new version of
cabal-install by doing `cabal install cabal-install`, neglect to make
sure that the newly installed cabal-install executable is in their path,
and continue to run the cabal-install executable they had before.  The
next time they do `cabal update`, they see the same message and become

This commit changes the message in question to be more informative and
helpful.  In particular, if the currently running version of
cabal-install is older than the newest version available from hackage,
the user will not be told simply that "there is a new version of
cabal-install available", but rather will be informed exactly what new
versions are available, and what version they are currently running,
along with a hint to change their $PATH variable if it turns out they're
not running the version of cabal-install they thought they were.
parent 0da666f3
......@@ -39,7 +39,9 @@ import qualified Data.ByteString.Lazy as BS
import Distribution.Client.GZipUtils (maybeDecompress)
import qualified Data.Map as Map
import System.FilePath (dropExtension)
import Data.List (intercalate)
import Data.Maybe (fromMaybe)
import Data.Version (showVersion)
import Control.Monad (unless)
-- | 'update' downloads the package list from all known servers
......@@ -73,13 +75,18 @@ checkForSelfUpgrade verbosity repos = do
preferredVersionRange = fromMaybe anyVersion (Map.lookup self prefs)
currentVersion = Paths_cabal_install.version
laterPreferredVersions =
[ packageVersion pkg
[ version
| pkg <- PackageIndex.lookupPackageName sourcePkgIndex self
, let version = packageVersion pkg
, version > currentVersion
, version `withinRange` preferredVersionRange ]
, version `withinRange` preferredVersionRange
unless (null laterPreferredVersions) $
notice verbosity $
"Note: there is a new version of cabal-install available.\n"
++ "To upgrade, run: cabal install cabal-install"
unless (null laterPreferredVersions) $ mapM_ (notice verbosity)
[ "Note: I am not the latest version of cabal-install."
, "These versions are available and are newer than me: "
++ (intercalate ", " . map showVersion) laterPreferredVersions
, "My version is: " ++ showVersion currentVersion
, "If you have already installed a newer version, and intended "
++ "to run it, maybe check your $PATH variable?"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment