Commit 729ac031 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov Committed by Mikhail Glushenkov

Allow specifying --minor without arguments.

parent cf3a3f9a
......@@ -1177,12 +1177,13 @@ The following flags are supported by the ``outdated`` command:
``--ignore`` *PACKAGENAMES*
Don't warn about outdated dependency version bounds for the packages in this
list.
``--minor`` *PACKAGENAMES*
``--minor`` *[PACKAGENAMES]*
Ignore major version bumps for these packages. E.g. if there's a version 2.0
of a package ``pkg`` on Hackage and the freeze file specifies the constraint
``pkg == 1.9``, ``cabal outdated --freeze --minor=pkg`` will only consider
the ``pkg`` outdated when there's a version of ``pkg`` on Hackage satisfying
``pkg > 1.9 && < 2.0``.
``pkg > 1.9 && < 2.0``. ``--minor`` can also be used without arguments, in
that case major version bumps are ignored for all packages.
Examples:
......
......@@ -8,7 +8,9 @@
-- dependencies in the package description file or freeze file.
-----------------------------------------------------------------------------
module Distribution.Client.Outdated ( outdated ) where
module Distribution.Client.Outdated ( outdated
, ListOutdatedSettings(..), listOutdated )
where
import Prelude ()
import Distribution.Client.Config
......@@ -57,8 +59,15 @@ outdated verbosity0 outdatedFlags repoContext comp platform = do
simpleOutput = fromFlagOrDefault False (outdatedSimpleOutput outdatedFlags)
quiet = fromFlagOrDefault False (outdatedQuiet outdatedFlags)
exitCode = fromFlagOrDefault quiet (outdatedExitCode outdatedFlags)
ignoreSet = S.fromList (outdatedIgnore outdatedFlags)
minorSet = S.fromList (outdatedMinor outdatedFlags)
ignorePred = let ignoreSet = S.fromList (outdatedIgnore outdatedFlags)
in \pkgname -> pkgname `S.member` ignoreSet
minorPred = case outdatedMinor outdatedFlags of
Nothing -> const False
Just IgnoreMajorVersionBumpsNone -> const False
Just IgnoreMajorVersionBumpsAll -> const True
Just (IgnoreMajorVersionBumpsSome pkgs) ->
let minorSet = S.fromList pkgs
in \pkgname -> pkgname `S.member` minorSet
verbosity = if quiet then silent else verbosity0
sourcePkgDb <- IndexUtils.getSourcePackages verbosity repoContext
......@@ -71,7 +80,7 @@ outdated verbosity0 outdatedFlags repoContext comp platform = do
debug verbosity $ "Dependencies loaded: "
++ (intercalate ", " $ map display deps)
let outdatedDeps = listOutdated deps pkgIndex
(ListOutdatedSettings ignoreSet minorSet)
(ListOutdatedSettings ignorePred minorPred)
when (not quiet) $
showResult verbosity outdatedDeps simpleOutput
if (exitCode && (not . null $ outdatedDeps))
......@@ -139,10 +148,10 @@ depsFromPkgDesc verbosity comp platform = do
-- | Various knobs for customising the behaviour of 'listOutdated'.
data ListOutdatedSettings = ListOutdatedSettings {
-- | A set of package names to ignore.
listOutdatedIgnoreSet :: S.Set PackageName,
-- | A set of package names for which major version bumps should be ignored.
listOutdatedMinorSet :: S.Set PackageName
-- | Should this package be ignored?
listOutdatedIgnorePred :: PackageName -> Bool,
-- | Should major version bumps should be ignored for this package?
listOutdatedMinorPred :: PackageName -> Bool
}
-- | Find all outdated dependencies.
......@@ -150,13 +159,13 @@ listOutdated :: [Dependency]
-> PackageIndex UnresolvedSourcePackage
-> ListOutdatedSettings
-> [(Dependency, Version)]
listOutdated deps pkgIndex settings =
listOutdated deps pkgIndex (ListOutdatedSettings ignorePred minorPred) =
mapMaybe isOutdated $ map simplifyDependency deps
where
isOutdated :: Dependency -> Maybe (Dependency, Version)
isOutdated dep
| depPkgName dep `S.member` (listOutdatedIgnoreSet settings) = Nothing
| otherwise =
| ignorePred (depPkgName dep) = Nothing
| otherwise =
let this = map packageVersion $ lookupDependency pkgIndex dep
latest = lookupLatest dep
in (\v -> (dep, v)) `fmap` isOutdated' this latest
......@@ -170,9 +179,9 @@ listOutdated deps pkgIndex settings =
lookupLatest :: Dependency -> [Version]
lookupLatest dep
| depPkgName dep `S.member` (listOutdatedMinorSet settings) =
| minorPred (depPkgName dep) =
map packageVersion $ lookupDependency pkgIndex (relaxMinor dep)
| otherwise =
| otherwise =
map packageVersion $ lookupPackageName pkgIndex (depPkgName dep)
relaxMinor :: Dependency -> Dependency
......
......@@ -33,7 +33,7 @@ module Distribution.Client.Setup
, fetchCommand, FetchFlags(..)
, freezeCommand, FreezeFlags(..)
, genBoundsCommand
, outdatedCommand, OutdatedFlags(..)
, outdatedCommand, OutdatedFlags(..), IgnoreMajorVersionBumps(..)
, getCommand, unpackCommand, GetFlags(..)
, checkCommand
, formatCommand
......@@ -859,6 +859,22 @@ genBoundsCommand = CommandUI {
-- * 'outdated' command
-- ------------------------------------------------------------
data IgnoreMajorVersionBumps = IgnoreMajorVersionBumpsNone
| IgnoreMajorVersionBumpsAll
| IgnoreMajorVersionBumpsSome [PackageName]
instance Monoid IgnoreMajorVersionBumps where
mempty = IgnoreMajorVersionBumpsNone
mappend = (<>)
instance Semigroup IgnoreMajorVersionBumps where
IgnoreMajorVersionBumpsNone <> r = r
l@IgnoreMajorVersionBumpsAll <> _ = l
l@(IgnoreMajorVersionBumpsSome _) <> IgnoreMajorVersionBumpsNone = l
(IgnoreMajorVersionBumpsSome _) <> r@IgnoreMajorVersionBumpsAll = r
(IgnoreMajorVersionBumpsSome a) <> (IgnoreMajorVersionBumpsSome b) =
IgnoreMajorVersionBumpsSome (a ++ b)
data OutdatedFlags = OutdatedFlags {
outdatedVerbosity :: Flag Verbosity,
outdatedFreezeFile :: Flag Bool,
......@@ -867,7 +883,7 @@ data OutdatedFlags = OutdatedFlags {
outdatedExitCode :: Flag Bool,
outdatedQuiet :: Flag Bool,
outdatedIgnore :: [PackageName],
outdatedMinor :: [PackageName]
outdatedMinor :: Maybe IgnoreMajorVersionBumps
}
defaultOutdatedFlags :: OutdatedFlags
......@@ -929,10 +945,22 @@ outdatedCommand = CommandUI {
,option [] ["minor"]
"Ignore major version bumps for these packages"
outdatedMinor (\v flags -> flags { outdatedMinor = v })
(reqArg "PKGS" pkgNameListParser (map display))
(optArg "PKGS" ignoreMajorVersionBumpsParser
(Just IgnoreMajorVersionBumpsAll) ignoreMajorVersionBumpsPrinter)
]
}
where
ignoreMajorVersionBumpsPrinter :: (Maybe IgnoreMajorVersionBumps)
-> [Maybe String]
ignoreMajorVersionBumpsPrinter Nothing = []
ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsNone)= []
ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsAll) = [Nothing]
ignoreMajorVersionBumpsPrinter (Just (IgnoreMajorVersionBumpsSome pkgs)) =
map (Just . display) $ pkgs
ignoreMajorVersionBumpsParser =
(Just . IgnoreMajorVersionBumpsSome) `fmap` pkgNameListParser
pkgNameListParser = readP_to_E
("Couldn't parse the list of package names: " ++)
(Parse.sepBy1 parse (Parse.char ','))
......
Markdown is supported
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