@@ -11,7 +11,6 @@ module Distribution.Client.CmdOutdated
11
11
import qualified Data.Set as Set
12
12
13
13
import Distribution.Client.Compat.Prelude
14
-
15
14
import Distribution.Client.Config
16
15
( SavedConfig
17
16
( savedGlobalFlags
@@ -27,7 +26,6 @@ import Distribution.Client.NixStyleOptions
27
26
import Distribution.Client.Outdated
28
27
( IgnoreMajorVersionBumps (.. )
29
28
, ListOutdatedSettings (.. )
30
- , OutdatedFlags (.. )
31
29
)
32
30
import qualified Distribution.Client.Outdated as V1Outdated
33
31
import Distribution.Client.ProjectConfig
@@ -46,7 +44,8 @@ import Distribution.Client.Sandbox
46
44
( loadConfigOrSandboxConfig
47
45
)
48
46
import Distribution.Client.Setup
49
- ( GlobalFlags (.. )
47
+ ( ConfigFlags (.. )
48
+ , GlobalFlags (.. )
50
49
, configCompilerAux'
51
50
, withRepoContext
52
51
)
@@ -56,14 +55,27 @@ import Distribution.Client.Types.PackageLocation
56
55
import Distribution.Client.Types.PackageSpecifier
57
56
( PackageSpecifier (.. )
58
57
)
58
+ import qualified Distribution.Compat.CharParsing as P
59
+ import Distribution.ReadE
60
+ ( parsecToReadE
61
+ )
59
62
import Distribution.Simple.Command
60
63
( CommandUI (.. )
64
+ , OptionField
65
+ , ShowOrParseArgs
66
+ , optArg
67
+ , option
68
+ , reqArg
61
69
, usageAlternatives
62
70
)
63
71
import Distribution.Simple.Flag
64
- ( flagToMaybe
72
+ ( Flag (.. )
73
+ , flagToMaybe
65
74
, fromFlagOrDefault
66
75
)
76
+ import Distribution.Simple.Setup
77
+ ( trueArg
78
+ )
67
79
import Distribution.Simple.Utils
68
80
( debug
69
81
, dieWithException
@@ -101,13 +113,13 @@ outdatedCommand =
101
113
{ commandName = " v2-outdated"
102
114
, commandSynopsis = " Check for outdated dependencies."
103
115
, commandUsage = usageAlternatives " v2-outdated" [" [FLAGS]" , " [PACKAGES]" ]
104
- , commandDefaultFlags = defaultNixStyleFlags V1Outdated. defaultOutdatedFlags
116
+ , commandDefaultFlags = defaultNixStyleFlags defaultOutdatedFlags
105
117
, commandDescription = Just $ \ _ ->
106
118
wrapText $
107
119
" Checks for outdated dependencies in the package description file "
108
120
++ " or freeze file"
109
121
, commandNotes = Nothing
110
- , commandOptions = nixStyleOptions V1Outdated. outdatedOptions
122
+ , commandOptions = nixStyleOptions outdatedOptions
111
123
}
112
124
113
125
-- | To a first approximation, the @outdated@ command runs the first phase of
@@ -133,10 +145,11 @@ outdatedAction flags _extraArgs globalFlags = do
133
145
sourcePkgDb <- IndexUtils. getSourcePackages verbosity repoContext
134
146
prjBaseCtxt <- establishProjectBaseContext verbosity cliConfig OtherCommand
135
147
pkgVerConstraints <-
136
- if | v1FreezeFile -> V1Outdated. depsFromFreezeFile verbosity
137
- | v2FreezeFile ->
138
- V1Outdated. depsFromNewFreezeFile verbosity globalFlags comp platform mprojectDir mprojectFile
139
- | otherwise -> pure $ extractPackageVersionConstraints (localPackages prjBaseCtxt)
148
+ if
149
+ | v1FreezeFile -> V1Outdated. depsFromFreezeFile verbosity
150
+ | v2FreezeFile ->
151
+ V1Outdated. depsFromNewFreezeFile verbosity globalFlags comp platform mprojectDir mprojectFile
152
+ | otherwise -> pure $ extractPackageVersionConstraints (localPackages prjBaseCtxt)
140
153
141
154
debug verbosity $
142
155
" Dependencies loaded: " ++ intercalate " , " (map prettyShow pkgVerConstraints)
@@ -155,7 +168,6 @@ outdatedAction flags _extraArgs globalFlags = do
155
168
globalFlags
156
169
flags
157
170
mempty -- ClientInstallFlags, not needed here
158
-
159
171
outdatedFlags :: OutdatedFlags
160
172
outdatedFlags = extraFlags flags
161
173
@@ -185,7 +197,29 @@ outdatedAction flags _extraArgs globalFlags = do
185
197
verbosity =
186
198
if quiet
187
199
then silent
188
- else fromFlagOrDefault normal (outdatedVerbosity outdatedFlags)
200
+ else fromFlagOrDefault normal (configVerbosity $ configFlags flags)
201
+
202
+ data OutdatedFlags = OutdatedFlags
203
+ { outdatedFreezeFile :: Flag Bool
204
+ , outdatedNewFreezeFile :: Flag Bool
205
+ , outdatedSimpleOutput :: Flag Bool
206
+ , outdatedExitCode :: Flag Bool
207
+ , outdatedQuiet :: Flag Bool
208
+ , outdatedIgnore :: [PackageName ]
209
+ , outdatedMinor :: Maybe IgnoreMajorVersionBumps
210
+ }
211
+
212
+ defaultOutdatedFlags :: OutdatedFlags
213
+ defaultOutdatedFlags =
214
+ OutdatedFlags
215
+ { outdatedFreezeFile = mempty
216
+ , outdatedNewFreezeFile = mempty
217
+ , outdatedSimpleOutput = mempty
218
+ , outdatedExitCode = mempty
219
+ , outdatedQuiet = mempty
220
+ , outdatedIgnore = mempty
221
+ , outdatedMinor = mempty
222
+ }
189
223
190
224
extractPackageVersionConstraints :: [PackageSpecifier (SourcePackage UnresolvedPkgLoc )] -> [PackageVersionConstraint ]
191
225
extractPackageVersionConstraints =
@@ -214,3 +248,78 @@ genericPackageDependencies gpd =
214
248
where
215
249
extract :: forall a confVar . Semigroup a => (UnqualComponentName , CondTree confVar [Dependency ] a ) -> [Dependency ]
216
250
extract = snd . ignoreConditions . snd
251
+
252
+ outdatedOptions :: ShowOrParseArgs -> [OptionField OutdatedFlags ]
253
+ outdatedOptions _showOrParseArgs =
254
+ [ option
255
+ []
256
+ [" freeze-file" , " v1-freeze-file" ]
257
+ " Act on the freeze file"
258
+ outdatedFreezeFile
259
+ (\ v flags -> flags{outdatedFreezeFile = v})
260
+ trueArg
261
+ , option
262
+ []
263
+ [" v2-freeze-file" , " new-freeze-file" ]
264
+ " Act on the new-style freeze file (default: cabal.project.freeze)"
265
+ outdatedNewFreezeFile
266
+ (\ v flags -> flags{outdatedNewFreezeFile = v})
267
+ trueArg
268
+ , option
269
+ []
270
+ [" simple-output" ]
271
+ " Only print names of outdated dependencies, one per line"
272
+ outdatedSimpleOutput
273
+ (\ v flags -> flags{outdatedSimpleOutput = v})
274
+ trueArg
275
+ , option
276
+ []
277
+ [" exit-code" ]
278
+ " Exit with non-zero when there are outdated dependencies"
279
+ outdatedExitCode
280
+ (\ v flags -> flags{outdatedExitCode = v})
281
+ trueArg
282
+ , option
283
+ [' q' ]
284
+ [" quiet" ]
285
+ " Don't print any output. Implies '--exit-code' and '-v0'"
286
+ outdatedQuiet
287
+ (\ v flags -> flags{outdatedQuiet = v})
288
+ trueArg
289
+ , option
290
+ []
291
+ [" ignore" ]
292
+ " Packages to ignore"
293
+ outdatedIgnore
294
+ (\ v flags -> flags{outdatedIgnore = v})
295
+ (reqArg " PKGS" pkgNameListParser (map prettyShow))
296
+ , option
297
+ []
298
+ [" minor" ]
299
+ " Ignore major version bumps for these packages"
300
+ outdatedMinor
301
+ (\ v flags -> flags{outdatedMinor = v})
302
+ ( optArg
303
+ " PKGS"
304
+ ignoreMajorVersionBumpsParser
305
+ (" " , Just IgnoreMajorVersionBumpsAll )
306
+ ignoreMajorVersionBumpsPrinter
307
+ )
308
+ ]
309
+ where
310
+ ignoreMajorVersionBumpsPrinter
311
+ :: Maybe IgnoreMajorVersionBumps
312
+ -> [Maybe String ]
313
+ ignoreMajorVersionBumpsPrinter Nothing = []
314
+ ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsNone ) = []
315
+ ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsAll ) = [Nothing ]
316
+ ignoreMajorVersionBumpsPrinter (Just (IgnoreMajorVersionBumpsSome pkgs)) =
317
+ map (Just . prettyShow) pkgs
318
+
319
+ ignoreMajorVersionBumpsParser =
320
+ (Just . IgnoreMajorVersionBumpsSome ) `fmap` pkgNameListParser
321
+
322
+ pkgNameListParser =
323
+ parsecToReadE
324
+ (" Couldn't parse the list of package names: " ++ )
325
+ (fmap toList (P. sepByNonEmpty parsec (P. char ' ,' )))
0 commit comments