Split sections support for GHC
[cabal.git] / cabal-install / Distribution / Client / Setup.hs
blobbcb7c1ad9a6b5f385d7cb52452b1ec1f22a60bfa
1 {-# LANGUAGE ScopedTypeVariables #-}
2 {-# LANGUAGE RecordWildCards #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE DeriveGeneric #-}
5 -----------------------------------------------------------------------------
6 -- |
7 -- Module : Distribution.Client.Setup
8 -- Copyright : (c) David Himmelstrup 2005
9 -- License : BSD-like
11 -- Maintainer : lemmih@gmail.com
12 -- Stability : provisional
13 -- Portability : portable
16 -----------------------------------------------------------------------------
17 module Distribution.Client.Setup
18 ( globalCommand, GlobalFlags(..), defaultGlobalFlags
19 , RepoContext(..), withRepoContext
20 , configureCommand, ConfigFlags(..), filterConfigureFlags
21 , configPackageDB', configCompilerAux'
22 , configureExCommand, ConfigExFlags(..), defaultConfigExFlags
23 , buildCommand, BuildFlags(..), BuildExFlags(..), SkipAddSourceDepsCheck(..)
24 , replCommand, testCommand, benchmarkCommand
25 , configureExOptions, reconfigureCommand
26 , installCommand, InstallFlags(..), installOptions, defaultInstallFlags
27 , defaultSolver, defaultMaxBackjumps
28 , listCommand, ListFlags(..)
29 , updateCommand, UpdateFlags(..), defaultUpdateFlags
30 , upgradeCommand
31 , uninstallCommand
32 , infoCommand, InfoFlags(..)
33 , fetchCommand, FetchFlags(..)
34 , freezeCommand, FreezeFlags(..)
35 , genBoundsCommand
36 , outdatedCommand, OutdatedFlags(..), IgnoreMajorVersionBumps(..)
37 , getCommand, unpackCommand, GetFlags(..)
38 , checkCommand
39 , formatCommand
40 , uploadCommand, UploadFlags(..), IsCandidate(..)
41 , reportCommand, ReportFlags(..)
42 , runCommand
43 , initCommand, IT.InitFlags(..)
44 , sdistCommand, SDistFlags(..), SDistExFlags(..), ArchiveFormat(..)
45 , win32SelfUpgradeCommand, Win32SelfUpgradeFlags(..)
46 , actAsSetupCommand, ActAsSetupFlags(..)
47 , sandboxCommand, defaultSandboxLocation, SandboxFlags(..)
48 , execCommand, ExecFlags(..), defaultExecFlags
49 , userConfigCommand, UserConfigFlags(..)
50 , manpageCommand
52 , applyFlagDefaults
53 , parsePackageArgs
54 --TODO: stop exporting these:
55 , showRepo
56 , parseRepo
57 , readRepo
58 ) where
60 import Prelude ()
61 import Distribution.Client.Compat.Prelude hiding (get)
63 import Distribution.Client.Types
64 ( Username(..), Password(..), RemoteRepo(..)
65 , AllowNewer(..), AllowOlder(..), RelaxDeps(..)
67 import Distribution.Client.BuildReports.Types
68 ( ReportLevel(..) )
69 import Distribution.Client.Dependency.Types
70 ( PreSolver(..) )
71 import Distribution.Client.IndexUtils.Timestamp
72 ( IndexState(..) )
73 import qualified Distribution.Client.Init.Types as IT
74 ( InitFlags(..), PackageType(..) )
75 import Distribution.Client.Targets
76 ( UserConstraint, readUserConstraint )
77 import Distribution.Utils.NubList
78 ( NubList, toNubList, fromNubList)
80 import Distribution.Solver.Types.ConstraintSource
81 import Distribution.Solver.Types.Settings
83 import Distribution.Simple.Compiler ( Compiler, PackageDB, PackageDBStack )
84 import Distribution.Simple.Program (ProgramDb, defaultProgramDb)
85 import Distribution.Simple.Command hiding (boolOpt, boolOpt')
86 import qualified Distribution.Simple.Command as Command
87 import Distribution.Simple.Configure
88 ( configCompilerAuxEx, interpretPackageDbFlags, computeEffectiveProfiling )
89 import qualified Distribution.Simple.Setup as Cabal
90 import Distribution.Simple.Setup
91 ( ConfigFlags(..), BuildFlags(..), ReplFlags
92 , TestFlags(..), BenchmarkFlags(..)
93 , SDistFlags(..), HaddockFlags(..)
94 , readPackageDbList, showPackageDbList
95 , Flag(..), toFlag, flagToMaybe, flagToList, maybeToFlag
96 , BooleanFlag(..), optionVerbosity
97 , boolOpt, boolOpt', trueArg, falseArg
98 , optionNumJobs )
99 import Distribution.Simple.InstallDirs
100 ( PathTemplate, InstallDirs(..)
101 , toPathTemplate, fromPathTemplate, combinePathTemplate )
102 import Distribution.Version
103 ( Version, mkVersion, nullVersion, anyVersion, thisVersion )
104 import Distribution.Package
105 ( PackageIdentifier, PackageName, packageName, packageVersion )
106 import Distribution.Types.Dependency
107 import Distribution.PackageDescription
108 ( BuildType(..), RepoKind(..) )
109 import Distribution.System ( Platform )
110 import Distribution.Text
111 ( Text(..), display )
112 import Distribution.ReadE
113 ( ReadE(..), readP_to_E, succeedReadE )
114 import qualified Distribution.Compat.ReadP as Parse
115 ( ReadP, char, munch1, pfail, sepBy1, (+++) )
116 import Distribution.ParseUtils
117 ( readPToMaybe )
118 import Distribution.Verbosity
119 ( Verbosity, lessVerbose, normal, verboseNoFlags, verboseNoTimestamp )
120 import Distribution.Simple.Utils
121 ( wrapText, wrapLine )
122 import Distribution.Client.GlobalFlags
123 ( GlobalFlags(..), defaultGlobalFlags
124 , RepoContext(..), withRepoContext
127 import Data.List
128 ( deleteFirstsBy )
129 import System.FilePath
130 ( (</>) )
131 import Network.URI
132 ( parseAbsoluteURI, uriToString )
134 applyFlagDefaults :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
135 -> (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
136 applyFlagDefaults (configFlags, configExFlags, installFlags, haddockFlags) =
137 ( commandDefaultFlags configureCommand <> configFlags
138 , defaultConfigExFlags <> configExFlags
139 , defaultInstallFlags <> installFlags
140 , Cabal.defaultHaddockFlags <> haddockFlags
143 globalCommand :: [Command action] -> CommandUI GlobalFlags
144 globalCommand commands = CommandUI {
145 commandName = "",
146 commandSynopsis =
147 "Command line interface to the Haskell Cabal infrastructure.",
148 commandUsage = \pname ->
149 "See http://www.haskell.org/cabal/ for more information.\n"
150 ++ "\n"
151 ++ "Usage: " ++ pname ++ " [GLOBAL FLAGS] [COMMAND [FLAGS]]\n",
152 commandDescription = Just $ \pname ->
154 commands' = commands ++ [commandAddAction helpCommandUI undefined]
155 cmdDescs = getNormalCommandDescriptions commands'
156 -- if new commands are added, we want them to appear even if they
157 -- are not included in the custom listing below. Thus, we calculate
158 -- the `otherCmds` list and append it under the `other` category.
159 -- Alternatively, a new testcase could be added that ensures that
160 -- the set of commands listed here is equal to the set of commands
161 -- that are actually available.
162 otherCmds = deleteFirstsBy (==) (map fst cmdDescs)
163 [ "help"
164 , "update"
165 , "install"
166 , "fetch"
167 , "list"
168 , "info"
169 , "user-config"
170 , "get"
171 , "init"
172 , "configure"
173 , "reconfigure"
174 , "build"
175 , "clean"
176 , "run"
177 , "repl"
178 , "test"
179 , "bench"
180 , "check"
181 , "sdist"
182 , "upload"
183 , "report"
184 , "freeze"
185 , "gen-bounds"
186 , "outdated"
187 , "doctest"
188 , "haddock"
189 , "hscolour"
190 , "copy"
191 , "register"
192 , "sandbox"
193 , "exec"
194 , "new-build"
195 , "new-configure"
196 , "new-repl"
197 , "new-freeze"
198 , "new-run"
199 , "new-test"
200 , "new-bench"
201 , "new-haddock"
203 maxlen = maximum $ [length name | (name, _) <- cmdDescs]
204 align str = str ++ replicate (maxlen - length str) ' '
205 startGroup n = " ["++n++"]"
206 par = ""
207 addCmd n = case lookup n cmdDescs of
208 Nothing -> ""
209 Just d -> " " ++ align n ++ " " ++ d
210 addCmdCustom n d = case lookup n cmdDescs of -- make sure that the
211 -- command still exists.
212 Nothing -> ""
213 Just _ -> " " ++ align n ++ " " ++ d
215 "Commands:\n"
216 ++ unlines (
217 [ startGroup "global"
218 , addCmd "update"
219 , addCmd "install"
220 , par
221 , addCmd "help"
222 , addCmd "info"
223 , addCmd "list"
224 , addCmd "fetch"
225 , addCmd "user-config"
226 , par
227 , startGroup "package"
228 , addCmd "get"
229 , addCmd "init"
230 , par
231 , addCmd "configure"
232 , addCmd "build"
233 , addCmd "clean"
234 , par
235 , addCmd "run"
236 , addCmd "repl"
237 , addCmd "test"
238 , addCmd "bench"
239 , par
240 , addCmd "check"
241 , addCmd "sdist"
242 , addCmd "upload"
243 , addCmd "report"
244 , par
245 , addCmd "freeze"
246 , addCmd "gen-bounds"
247 , addCmd "outdated"
248 , addCmd "doctest"
249 , addCmd "haddock"
250 , addCmd "hscolour"
251 , addCmd "copy"
252 , addCmd "register"
253 , addCmd "reconfigure"
254 , par
255 , startGroup "sandbox"
256 , addCmd "sandbox"
257 , addCmd "exec"
258 , addCmdCustom "repl" "Open interpreter with access to sandbox packages."
259 , par
260 , startGroup "new-style projects (beta)"
261 , addCmd "new-build"
262 , addCmd "new-configure"
263 , addCmd "new-repl"
264 , addCmd "new-run"
265 , addCmd "new-test"
266 , addCmd "new-bench"
267 , addCmd "new-freeze"
268 , addCmd "new-haddock"
269 ] ++ if null otherCmds then [] else par
270 :startGroup "other"
271 :[addCmd n | n <- otherCmds])
272 ++ "\n"
273 ++ "For more information about a command use:\n"
274 ++ " " ++ pname ++ " COMMAND --help\n"
275 ++ "or " ++ pname ++ " help COMMAND\n"
276 ++ "\n"
277 ++ "To install Cabal packages from hackage use:\n"
278 ++ " " ++ pname ++ " install foo [--dry-run]\n"
279 ++ "\n"
280 ++ "Occasionally you need to update the list of available packages:\n"
281 ++ " " ++ pname ++ " update\n",
282 commandNotes = Nothing,
283 commandDefaultFlags = mempty,
284 commandOptions = args
286 where
287 args :: ShowOrParseArgs -> [OptionField GlobalFlags]
288 args ShowArgs = argsShown
289 args ParseArgs = argsShown ++ argsNotShown
291 -- arguments we want to show in the help
292 argsShown :: [OptionField GlobalFlags]
293 argsShown = [
294 option ['V'] ["version"]
295 "Print version information"
296 globalVersion (\v flags -> flags { globalVersion = v })
297 trueArg
299 ,option [] ["numeric-version"]
300 "Print just the version number"
301 globalNumericVersion (\v flags -> flags { globalNumericVersion = v })
302 trueArg
304 ,option [] ["config-file"]
305 "Set an alternate location for the config file"
306 globalConfigFile (\v flags -> flags { globalConfigFile = v })
307 (reqArgFlag "FILE")
309 ,option [] ["sandbox-config-file"]
310 "Set an alternate location for the sandbox config file (default: './cabal.sandbox.config')"
311 globalSandboxConfigFile (\v flags -> flags { globalSandboxConfigFile = v })
312 (reqArgFlag "FILE")
314 ,option [] ["default-user-config"]
315 "Set a location for a cabal.config file for projects without their own cabal.config freeze file."
316 globalConstraintsFile (\v flags -> flags {globalConstraintsFile = v})
317 (reqArgFlag "FILE")
319 ,option [] ["require-sandbox"]
320 "requiring the presence of a sandbox for sandbox-aware commands"
321 globalRequireSandbox (\v flags -> flags { globalRequireSandbox = v })
322 (boolOpt' ([], ["require-sandbox"]) ([], ["no-require-sandbox"]))
324 ,option [] ["ignore-sandbox"]
325 "Ignore any existing sandbox"
326 globalIgnoreSandbox (\v flags -> flags { globalIgnoreSandbox = v })
327 trueArg
329 ,option [] ["ignore-expiry"]
330 "Ignore expiry dates on signed metadata (use only in exceptional circumstances)"
331 globalIgnoreExpiry (\v flags -> flags { globalIgnoreExpiry = v })
332 trueArg
334 ,option [] ["http-transport"]
335 "Set a transport for http(s) requests. Accepts 'curl', 'wget', 'powershell', and 'plain-http'. (default: 'curl')"
336 globalHttpTransport (\v flags -> flags { globalHttpTransport = v })
337 (reqArgFlag "HttpTransport")
338 ,option [] ["nix"]
339 "Nix integration: run commands through nix-shell if a 'shell.nix' file exists"
340 globalNix (\v flags -> flags { globalNix = v })
341 (boolOpt [] [])
344 -- arguments we don't want shown in the help
345 argsNotShown :: [OptionField GlobalFlags]
346 argsNotShown = [
347 option [] ["remote-repo"]
348 "The name and url for a remote repository"
349 globalRemoteRepos (\v flags -> flags { globalRemoteRepos = v })
350 (reqArg' "NAME:URL" (toNubList . maybeToList . readRepo) (map showRepo . fromNubList))
352 ,option [] ["remote-repo-cache"]
353 "The location where downloads from all remote repos are cached"
354 globalCacheDir (\v flags -> flags { globalCacheDir = v })
355 (reqArgFlag "DIR")
357 ,option [] ["local-repo"]
358 "The location of a local repository"
359 globalLocalRepos (\v flags -> flags { globalLocalRepos = v })
360 (reqArg' "DIR" (\x -> toNubList [x]) fromNubList)
362 ,option [] ["logs-dir"]
363 "The location to put log files"
364 globalLogsDir (\v flags -> flags { globalLogsDir = v })
365 (reqArgFlag "DIR")
367 ,option [] ["world-file"]
368 "The location of the world file"
369 globalWorldFile (\v flags -> flags { globalWorldFile = v })
370 (reqArgFlag "FILE")
372 ,option [] ["store-dir"]
373 "The location of the nix-local-build store"
374 globalStoreDir (\v flags -> flags { globalStoreDir = v })
375 (reqArgFlag "DIR")
378 -- ------------------------------------------------------------
379 -- * Config flags
380 -- ------------------------------------------------------------
382 configureCommand :: CommandUI ConfigFlags
383 configureCommand = c
384 { commandDefaultFlags = mempty
385 , commandNotes = Just $ \pname -> (case commandNotes c of
386 Nothing -> ""
387 Just n -> n pname ++ "\n")
388 ++ "Examples:\n"
389 ++ " " ++ pname ++ " configure\n"
390 ++ " Configure with defaults;\n"
391 ++ " " ++ pname ++ " configure --enable-tests -fcustomflag\n"
392 ++ " Configure building package including tests,\n"
393 ++ " with some package-specific flag.\n"
395 where
396 c = Cabal.configureCommand defaultProgramDb
398 configureOptions :: ShowOrParseArgs -> [OptionField ConfigFlags]
399 configureOptions = commandOptions configureCommand
401 -- | Given some 'ConfigFlags' for the version of Cabal that
402 -- cabal-install was built with, and a target older 'Version' of
403 -- Cabal that we want to pass these flags to, convert the
404 -- flags into a form that will be accepted by the older
405 -- Setup script. Generally speaking, this just means filtering
406 -- out flags that the old Cabal library doesn't understand, but
407 -- in some cases it may also mean "emulating" a feature using
408 -- some more legacy flags.
409 filterConfigureFlags :: ConfigFlags -> Version -> ConfigFlags
410 filterConfigureFlags flags cabalLibVersion
411 -- NB: we expect the latest version to be the most common case,
412 -- so test it first.
413 | cabalLibVersion >= mkVersion [2,1,0] = flags_latest
414 -- The naming convention is that flags_version gives flags with
415 -- all flags *introduced* in version eliminated.
416 -- It is NOT the latest version of Cabal library that
417 -- these flags work for; version of introduction is a more
418 -- natural metric.
419 | cabalLibVersion < mkVersion [1,3,10] = flags_1_3_10
420 | cabalLibVersion < mkVersion [1,10,0] = flags_1_10_0
421 | cabalLibVersion < mkVersion [1,12,0] = flags_1_12_0
422 | cabalLibVersion < mkVersion [1,14,0] = flags_1_14_0
423 | cabalLibVersion < mkVersion [1,18,0] = flags_1_18_0
424 | cabalLibVersion < mkVersion [1,19,1] = flags_1_19_1
425 | cabalLibVersion < mkVersion [1,19,2] = flags_1_19_2
426 | cabalLibVersion < mkVersion [1,21,1] = flags_1_21_1
427 | cabalLibVersion < mkVersion [1,22,0] = flags_1_22_0
428 | cabalLibVersion < mkVersion [1,23,0] = flags_1_23_0
429 | cabalLibVersion < mkVersion [1,25,0] = flags_1_25_0
430 | cabalLibVersion < mkVersion [2,1,0] = flags_2_1_0
431 | otherwise = flags_latest
432 where
433 flags_latest = flags {
434 -- Cabal >= 1.19.1 uses '--dependency' and does not need '--constraint'.
435 configConstraints = []
438 flags_2_1_0 = flags_latest {
439 -- Cabal < 2.1 doesn't know about -v +timestamp modifier
440 configVerbosity = fmap verboseNoTimestamp (configVerbosity flags_latest)
441 -- Cabal < 2.1 doesn't know about --<enable|disable>-static
442 , configStaticLib = NoFlag
443 , configSplitSections = NoFlag
446 flags_1_25_0 = flags_2_1_0 {
447 -- Cabal < 1.25.0 doesn't know about --dynlibdir.
448 configInstallDirs = configInstallDirs_1_25_0,
449 -- Cabal < 1.25 doesn't have extended verbosity syntax
450 configVerbosity = fmap verboseNoFlags (configVerbosity flags_2_1_0),
451 -- Cabal < 1.25 doesn't support --deterministic
452 configDeterministic = mempty
454 configInstallDirs_1_25_0 = let dirs = configInstallDirs flags in
455 dirs { dynlibdir = NoFlag
456 , libexecsubdir = NoFlag
457 , libexecdir = maybeToFlag $
458 combinePathTemplate <$> flagToMaybe (libexecdir dirs)
459 <*> flagToMaybe (libexecsubdir dirs)
461 -- Cabal < 1.23 doesn't know about '--profiling-detail'.
462 -- Cabal < 1.23 has a hacked up version of 'enable-profiling'
463 -- which we shouldn't use.
464 (tryLibProfiling, tryExeProfiling) = computeEffectiveProfiling flags
465 flags_1_23_0 = flags_1_25_0 { configProfDetail = NoFlag
466 , configProfLibDetail = NoFlag
467 , configIPID = NoFlag
468 , configProf = NoFlag
469 , configProfExe = Flag tryExeProfiling
470 , configProfLib = Flag tryLibProfiling
473 -- Cabal < 1.22 doesn't know about '--disable-debug-info'.
474 flags_1_22_0 = flags_1_23_0 { configDebugInfo = NoFlag }
476 -- Cabal < 1.21.1 doesn't know about 'disable-relocatable'
477 -- Cabal < 1.21.1 doesn't know about 'enable-profiling'
478 -- (but we already dealt with it in flags_1_23_0)
479 flags_1_21_1 =
480 flags_1_22_0 { configRelocatable = NoFlag
481 , configCoverage = NoFlag
482 , configLibCoverage = configCoverage flags
484 -- Cabal < 1.19.2 doesn't know about '--exact-configuration' and
485 -- '--enable-library-stripping'.
486 flags_1_19_2 = flags_1_21_1 { configExactConfiguration = NoFlag
487 , configStripLibs = NoFlag }
488 -- Cabal < 1.19.1 uses '--constraint' instead of '--dependency'.
489 flags_1_19_1 = flags_1_19_2 { configDependencies = []
490 , configConstraints = configConstraints flags }
491 -- Cabal < 1.18.0 doesn't know about --extra-prog-path and --sysconfdir.
492 flags_1_18_0 = flags_1_19_1 { configProgramPathExtra = toNubList []
493 , configInstallDirs = configInstallDirs_1_18_0}
494 configInstallDirs_1_18_0 = (configInstallDirs flags_1_19_1) { sysconfdir = NoFlag }
495 -- Cabal < 1.14.0 doesn't know about '--disable-benchmarks'.
496 flags_1_14_0 = flags_1_18_0 { configBenchmarks = NoFlag }
497 -- Cabal < 1.12.0 doesn't know about '--enable/disable-executable-dynamic'
498 -- and '--enable/disable-library-coverage'.
499 flags_1_12_0 = flags_1_14_0 { configLibCoverage = NoFlag
500 , configDynExe = NoFlag }
501 -- Cabal < 1.10.0 doesn't know about '--disable-tests'.
502 flags_1_10_0 = flags_1_12_0 { configTests = NoFlag }
503 -- Cabal < 1.3.10 does not grok the '--constraints' flag.
504 flags_1_3_10 = flags_1_10_0 { configConstraints = [] }
506 -- | Get the package database settings from 'ConfigFlags', accounting for
507 -- @--package-db@ and @--user@ flags.
508 configPackageDB' :: ConfigFlags -> PackageDBStack
509 configPackageDB' cfg =
510 interpretPackageDbFlags userInstall (configPackageDBs cfg)
511 where
512 userInstall = Cabal.fromFlagOrDefault True (configUserInstall cfg)
514 -- | Configure the compiler, but reduce verbosity during this step.
515 configCompilerAux' :: ConfigFlags -> IO (Compiler, Platform, ProgramDb)
516 configCompilerAux' configFlags =
517 configCompilerAuxEx configFlags
518 --FIXME: make configCompilerAux use a sensible verbosity
519 { configVerbosity = fmap lessVerbose (configVerbosity configFlags) }
521 -- ------------------------------------------------------------
522 -- * Config extra flags
523 -- ------------------------------------------------------------
525 -- | cabal configure takes some extra flags beyond runghc Setup configure
527 data ConfigExFlags = ConfigExFlags {
528 configCabalVersion :: Flag Version,
529 configExConstraints:: [(UserConstraint, ConstraintSource)],
530 configPreferences :: [Dependency],
531 configSolver :: Flag PreSolver,
532 configAllowNewer :: Maybe AllowNewer,
533 configAllowOlder :: Maybe AllowOlder
535 deriving (Eq, Generic)
537 defaultConfigExFlags :: ConfigExFlags
538 defaultConfigExFlags = mempty { configSolver = Flag defaultSolver }
540 configureExCommand :: CommandUI (ConfigFlags, ConfigExFlags)
541 configureExCommand = configureCommand {
542 commandDefaultFlags = (mempty, defaultConfigExFlags),
543 commandOptions = \showOrParseArgs ->
544 liftOptions fst setFst
545 (filter ((`notElem` ["constraint", "dependency", "exact-configuration"])
546 . optionName) $ configureOptions showOrParseArgs)
547 ++ liftOptions snd setSnd
548 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
550 where
551 setFst a (_,b) = (a,b)
552 setSnd b (a,_) = (a,b)
554 configureExOptions :: ShowOrParseArgs
555 -> ConstraintSource
556 -> [OptionField ConfigExFlags]
557 configureExOptions _showOrParseArgs src =
558 [ option [] ["cabal-lib-version"]
559 ("Select which version of the Cabal lib to use to build packages "
560 ++ "(useful for testing).")
561 configCabalVersion (\v flags -> flags { configCabalVersion = v })
562 (reqArg "VERSION" (readP_to_E ("Cannot parse cabal lib version: "++)
563 (fmap toFlag parse))
564 (map display . flagToList))
565 , option [] ["constraint"]
566 "Specify constraints on a package (version, installed/source, flags)"
567 configExConstraints (\v flags -> flags { configExConstraints = v })
568 (reqArg "CONSTRAINT"
569 ((\x -> [(x, src)]) `fmap` ReadE readUserConstraint)
570 (map $ display . fst))
572 , option [] ["preference"]
573 "Specify preferences (soft constraints) on the version of a package"
574 configPreferences (\v flags -> flags { configPreferences = v })
575 (reqArg "CONSTRAINT"
576 (readP_to_E (const "dependency expected")
577 (fmap (\x -> [x]) parse))
578 (map display))
580 , optionSolver configSolver (\v flags -> flags { configSolver = v })
582 , option [] ["allow-older"]
583 ("Ignore lower bounds in all dependencies or DEPS")
584 (fmap unAllowOlder . configAllowOlder)
585 (\v flags -> flags { configAllowOlder = fmap AllowOlder v})
586 (optArg "DEPS"
587 (readP_to_E ("Cannot parse the list of packages: " ++) relaxDepsParser)
588 (Just RelaxDepsAll) relaxDepsPrinter)
590 , option [] ["allow-newer"]
591 ("Ignore upper bounds in all dependencies or DEPS")
592 (fmap unAllowNewer . configAllowNewer)
593 (\v flags -> flags { configAllowNewer = fmap AllowNewer v})
594 (optArg "DEPS"
595 (readP_to_E ("Cannot parse the list of packages: " ++) relaxDepsParser)
596 (Just RelaxDepsAll) relaxDepsPrinter)
601 relaxDepsParser :: Parse.ReadP r (Maybe RelaxDeps)
602 relaxDepsParser =
603 (Just . RelaxDepsSome) `fmap` Parse.sepBy1 parse (Parse.char ',')
605 relaxDepsPrinter :: (Maybe RelaxDeps) -> [Maybe String]
606 relaxDepsPrinter Nothing = []
607 relaxDepsPrinter (Just RelaxDepsAll) = [Nothing]
608 relaxDepsPrinter (Just (RelaxDepsSome pkgs)) = map (Just . display) $ pkgs
611 instance Monoid ConfigExFlags where
612 mempty = gmempty
613 mappend = (<>)
615 instance Semigroup ConfigExFlags where
616 (<>) = gmappend
618 reconfigureCommand :: CommandUI (ConfigFlags, ConfigExFlags)
619 reconfigureCommand
620 = configureExCommand
621 { commandName = "reconfigure"
622 , commandSynopsis = "Reconfigure the package if necessary."
623 , commandDescription = Just $ \pname -> wrapText $
624 "Run `configure` with the most recently used flags, or append FLAGS "
625 ++ "to the most recently used configuration. "
626 ++ "Accepts the same flags as `" ++ pname ++ " configure'. "
627 ++ "If the package has never been configured, the default flags are "
628 ++ "used."
629 , commandNotes = Just $ \pname ->
630 "Examples:\n"
631 ++ " " ++ pname ++ " reconfigure\n"
632 ++ " Configure with the most recently used flags.\n"
633 ++ " " ++ pname ++ " reconfigure -w PATH\n"
634 ++ " Reconfigure with the most recently used flags,\n"
635 ++ " but use the compiler at PATH.\n\n"
636 , commandUsage = usageAlternatives "reconfigure" [ "[FLAGS]" ]
637 , commandDefaultFlags = mempty
640 -- ------------------------------------------------------------
641 -- * Build flags
642 -- ------------------------------------------------------------
644 data SkipAddSourceDepsCheck =
645 SkipAddSourceDepsCheck | DontSkipAddSourceDepsCheck
646 deriving Eq
648 data BuildExFlags = BuildExFlags {
649 buildOnly :: Flag SkipAddSourceDepsCheck
650 } deriving Generic
652 buildExOptions :: ShowOrParseArgs -> [OptionField BuildExFlags]
653 buildExOptions _showOrParseArgs =
654 option [] ["only"]
655 "Don't reinstall add-source dependencies (sandbox-only)"
656 buildOnly (\v flags -> flags { buildOnly = v })
657 (noArg (Flag SkipAddSourceDepsCheck))
659 : []
661 buildCommand :: CommandUI (BuildFlags, BuildExFlags)
662 buildCommand = parent {
663 commandDefaultFlags = (commandDefaultFlags parent, mempty),
664 commandOptions =
665 \showOrParseArgs -> liftOptions fst setFst
666 (commandOptions parent showOrParseArgs)
668 liftOptions snd setSnd (buildExOptions showOrParseArgs)
670 where
671 setFst a (_,b) = (a,b)
672 setSnd b (a,_) = (a,b)
674 parent = Cabal.buildCommand defaultProgramDb
676 instance Monoid BuildExFlags where
677 mempty = gmempty
678 mappend = (<>)
680 instance Semigroup BuildExFlags where
681 (<>) = gmappend
683 -- ------------------------------------------------------------
684 -- * Repl command
685 -- ------------------------------------------------------------
687 replCommand :: CommandUI (ReplFlags, BuildExFlags)
688 replCommand = parent {
689 commandDefaultFlags = (commandDefaultFlags parent, mempty),
690 commandOptions =
691 \showOrParseArgs -> liftOptions fst setFst
692 (commandOptions parent showOrParseArgs)
694 liftOptions snd setSnd (buildExOptions showOrParseArgs)
696 where
697 setFst a (_,b) = (a,b)
698 setSnd b (a,_) = (a,b)
700 parent = Cabal.replCommand defaultProgramDb
702 -- ------------------------------------------------------------
703 -- * Test command
704 -- ------------------------------------------------------------
706 testCommand :: CommandUI (TestFlags, BuildFlags, BuildExFlags)
707 testCommand = parent {
708 commandDefaultFlags = (commandDefaultFlags parent,
709 Cabal.defaultBuildFlags, mempty),
710 commandOptions =
711 \showOrParseArgs -> liftOptions get1 set1
712 (commandOptions parent showOrParseArgs)
714 liftOptions get2 set2
715 (Cabal.buildOptions progDb showOrParseArgs)
717 liftOptions get3 set3 (buildExOptions showOrParseArgs)
719 where
720 get1 (a,_,_) = a; set1 a (_,b,c) = (a,b,c)
721 get2 (_,b,_) = b; set2 b (a,_,c) = (a,b,c)
722 get3 (_,_,c) = c; set3 c (a,b,_) = (a,b,c)
724 parent = Cabal.testCommand
725 progDb = defaultProgramDb
727 -- ------------------------------------------------------------
728 -- * Bench command
729 -- ------------------------------------------------------------
731 benchmarkCommand :: CommandUI (BenchmarkFlags, BuildFlags, BuildExFlags)
732 benchmarkCommand = parent {
733 commandDefaultFlags = (commandDefaultFlags parent,
734 Cabal.defaultBuildFlags, mempty),
735 commandOptions =
736 \showOrParseArgs -> liftOptions get1 set1
737 (commandOptions parent showOrParseArgs)
739 liftOptions get2 set2
740 (Cabal.buildOptions progDb showOrParseArgs)
742 liftOptions get3 set3 (buildExOptions showOrParseArgs)
744 where
745 get1 (a,_,_) = a; set1 a (_,b,c) = (a,b,c)
746 get2 (_,b,_) = b; set2 b (a,_,c) = (a,b,c)
747 get3 (_,_,c) = c; set3 c (a,b,_) = (a,b,c)
749 parent = Cabal.benchmarkCommand
750 progDb = defaultProgramDb
752 -- ------------------------------------------------------------
753 -- * Fetch command
754 -- ------------------------------------------------------------
756 data FetchFlags = FetchFlags {
757 -- fetchOutput :: Flag FilePath,
758 fetchDeps :: Flag Bool,
759 fetchDryRun :: Flag Bool,
760 fetchSolver :: Flag PreSolver,
761 fetchMaxBackjumps :: Flag Int,
762 fetchReorderGoals :: Flag ReorderGoals,
763 fetchCountConflicts :: Flag CountConflicts,
764 fetchIndependentGoals :: Flag IndependentGoals,
765 fetchShadowPkgs :: Flag ShadowPkgs,
766 fetchStrongFlags :: Flag StrongFlags,
767 fetchAllowBootLibInstalls :: Flag AllowBootLibInstalls,
768 fetchVerbosity :: Flag Verbosity
771 defaultFetchFlags :: FetchFlags
772 defaultFetchFlags = FetchFlags {
773 -- fetchOutput = mempty,
774 fetchDeps = toFlag True,
775 fetchDryRun = toFlag False,
776 fetchSolver = Flag defaultSolver,
777 fetchMaxBackjumps = Flag defaultMaxBackjumps,
778 fetchReorderGoals = Flag (ReorderGoals False),
779 fetchCountConflicts = Flag (CountConflicts True),
780 fetchIndependentGoals = Flag (IndependentGoals False),
781 fetchShadowPkgs = Flag (ShadowPkgs False),
782 fetchStrongFlags = Flag (StrongFlags False),
783 fetchAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
784 fetchVerbosity = toFlag normal
787 fetchCommand :: CommandUI FetchFlags
788 fetchCommand = CommandUI {
789 commandName = "fetch",
790 commandSynopsis = "Downloads packages for later installation.",
791 commandUsage = usageAlternatives "fetch" [ "[FLAGS] PACKAGES"
793 commandDescription = Just $ \_ ->
794 "Note that it currently is not possible to fetch the dependencies for a\n"
795 ++ "package in the current directory.\n",
796 commandNotes = Nothing,
797 commandDefaultFlags = defaultFetchFlags,
798 commandOptions = \ showOrParseArgs -> [
799 optionVerbosity fetchVerbosity (\v flags -> flags { fetchVerbosity = v })
801 -- , option "o" ["output"]
802 -- "Put the package(s) somewhere specific rather than the usual cache."
803 -- fetchOutput (\v flags -> flags { fetchOutput = v })
804 -- (reqArgFlag "PATH")
806 , option [] ["dependencies", "deps"]
807 "Resolve and fetch dependencies (default)"
808 fetchDeps (\v flags -> flags { fetchDeps = v })
809 trueArg
811 , option [] ["no-dependencies", "no-deps"]
812 "Ignore dependencies"
813 fetchDeps (\v flags -> flags { fetchDeps = v })
814 falseArg
816 , option [] ["dry-run"]
817 "Do not install anything, only print what would be installed."
818 fetchDryRun (\v flags -> flags { fetchDryRun = v })
819 trueArg
821 ] ++
823 optionSolver fetchSolver (\v flags -> flags { fetchSolver = v }) :
824 optionSolverFlags showOrParseArgs
825 fetchMaxBackjumps (\v flags -> flags { fetchMaxBackjumps = v })
826 fetchReorderGoals (\v flags -> flags { fetchReorderGoals = v })
827 fetchCountConflicts (\v flags -> flags { fetchCountConflicts = v })
828 fetchIndependentGoals (\v flags -> flags { fetchIndependentGoals = v })
829 fetchShadowPkgs (\v flags -> flags { fetchShadowPkgs = v })
830 fetchStrongFlags (\v flags -> flags { fetchStrongFlags = v })
831 fetchAllowBootLibInstalls (\v flags -> flags { fetchAllowBootLibInstalls = v })
835 -- ------------------------------------------------------------
836 -- * Freeze command
837 -- ------------------------------------------------------------
839 data FreezeFlags = FreezeFlags {
840 freezeDryRun :: Flag Bool,
841 freezeTests :: Flag Bool,
842 freezeBenchmarks :: Flag Bool,
843 freezeSolver :: Flag PreSolver,
844 freezeMaxBackjumps :: Flag Int,
845 freezeReorderGoals :: Flag ReorderGoals,
846 freezeCountConflicts :: Flag CountConflicts,
847 freezeIndependentGoals :: Flag IndependentGoals,
848 freezeShadowPkgs :: Flag ShadowPkgs,
849 freezeStrongFlags :: Flag StrongFlags,
850 freezeAllowBootLibInstalls :: Flag AllowBootLibInstalls,
851 freezeVerbosity :: Flag Verbosity
854 defaultFreezeFlags :: FreezeFlags
855 defaultFreezeFlags = FreezeFlags {
856 freezeDryRun = toFlag False,
857 freezeTests = toFlag False,
858 freezeBenchmarks = toFlag False,
859 freezeSolver = Flag defaultSolver,
860 freezeMaxBackjumps = Flag defaultMaxBackjumps,
861 freezeReorderGoals = Flag (ReorderGoals False),
862 freezeCountConflicts = Flag (CountConflicts True),
863 freezeIndependentGoals = Flag (IndependentGoals False),
864 freezeShadowPkgs = Flag (ShadowPkgs False),
865 freezeStrongFlags = Flag (StrongFlags False),
866 freezeAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
867 freezeVerbosity = toFlag normal
870 freezeCommand :: CommandUI FreezeFlags
871 freezeCommand = CommandUI {
872 commandName = "freeze",
873 commandSynopsis = "Freeze dependencies.",
874 commandDescription = Just $ \_ -> wrapText $
875 "Calculates a valid set of dependencies and their exact versions. "
876 ++ "If successful, saves the result to the file `cabal.config`.\n"
877 ++ "\n"
878 ++ "The package versions specified in `cabal.config` will be used for "
879 ++ "any future installs.\n"
880 ++ "\n"
881 ++ "An existing `cabal.config` is ignored and overwritten.\n",
882 commandNotes = Nothing,
883 commandUsage = usageFlags "freeze",
884 commandDefaultFlags = defaultFreezeFlags,
885 commandOptions = \ showOrParseArgs -> [
886 optionVerbosity freezeVerbosity
887 (\v flags -> flags { freezeVerbosity = v })
889 , option [] ["dry-run"]
890 "Do not freeze anything, only print what would be frozen"
891 freezeDryRun (\v flags -> flags { freezeDryRun = v })
892 trueArg
894 , option [] ["tests"]
895 ("freezing of the dependencies of any tests suites "
896 ++ "in the package description file.")
897 freezeTests (\v flags -> flags { freezeTests = v })
898 (boolOpt [] [])
900 , option [] ["benchmarks"]
901 ("freezing of the dependencies of any benchmarks suites "
902 ++ "in the package description file.")
903 freezeBenchmarks (\v flags -> flags { freezeBenchmarks = v })
904 (boolOpt [] [])
906 ] ++
908 optionSolver
909 freezeSolver (\v flags -> flags { freezeSolver = v }):
910 optionSolverFlags showOrParseArgs
911 freezeMaxBackjumps (\v flags -> flags { freezeMaxBackjumps = v })
912 freezeReorderGoals (\v flags -> flags { freezeReorderGoals = v })
913 freezeCountConflicts (\v flags -> flags { freezeCountConflicts = v })
914 freezeIndependentGoals (\v flags -> flags { freezeIndependentGoals = v })
915 freezeShadowPkgs (\v flags -> flags { freezeShadowPkgs = v })
916 freezeStrongFlags (\v flags -> flags { freezeStrongFlags = v })
917 freezeAllowBootLibInstalls (\v flags -> flags { freezeAllowBootLibInstalls = v })
921 -- ------------------------------------------------------------
922 -- * 'gen-bounds' command
923 -- ------------------------------------------------------------
925 genBoundsCommand :: CommandUI FreezeFlags
926 genBoundsCommand = CommandUI {
927 commandName = "gen-bounds",
928 commandSynopsis = "Generate dependency bounds.",
929 commandDescription = Just $ \_ -> wrapText $
930 "Generates bounds for all dependencies that do not currently have them. "
931 ++ "Generated bounds are printed to stdout. "
932 ++ "You can then paste them into your .cabal file.\n"
933 ++ "\n",
934 commandNotes = Nothing,
935 commandUsage = usageFlags "gen-bounds",
936 commandDefaultFlags = defaultFreezeFlags,
937 commandOptions = \ _ -> [
938 optionVerbosity freezeVerbosity (\v flags -> flags { freezeVerbosity = v })
942 -- ------------------------------------------------------------
943 -- * 'outdated' command
944 -- ------------------------------------------------------------
946 data IgnoreMajorVersionBumps = IgnoreMajorVersionBumpsNone
947 | IgnoreMajorVersionBumpsAll
948 | IgnoreMajorVersionBumpsSome [PackageName]
950 instance Monoid IgnoreMajorVersionBumps where
951 mempty = IgnoreMajorVersionBumpsNone
952 mappend = (<>)
954 instance Semigroup IgnoreMajorVersionBumps where
955 IgnoreMajorVersionBumpsNone <> r = r
956 l@IgnoreMajorVersionBumpsAll <> _ = l
957 l@(IgnoreMajorVersionBumpsSome _) <> IgnoreMajorVersionBumpsNone = l
958 (IgnoreMajorVersionBumpsSome _) <> r@IgnoreMajorVersionBumpsAll = r
959 (IgnoreMajorVersionBumpsSome a) <> (IgnoreMajorVersionBumpsSome b) =
960 IgnoreMajorVersionBumpsSome (a ++ b)
962 data OutdatedFlags = OutdatedFlags {
963 outdatedVerbosity :: Flag Verbosity,
964 outdatedFreezeFile :: Flag Bool,
965 outdatedNewFreezeFile :: Flag Bool,
966 outdatedSimpleOutput :: Flag Bool,
967 outdatedExitCode :: Flag Bool,
968 outdatedQuiet :: Flag Bool,
969 outdatedIgnore :: [PackageName],
970 outdatedMinor :: Maybe IgnoreMajorVersionBumps
973 defaultOutdatedFlags :: OutdatedFlags
974 defaultOutdatedFlags = OutdatedFlags {
975 outdatedVerbosity = toFlag normal,
976 outdatedFreezeFile = mempty,
977 outdatedNewFreezeFile = mempty,
978 outdatedSimpleOutput = mempty,
979 outdatedExitCode = mempty,
980 outdatedQuiet = mempty,
981 outdatedIgnore = mempty,
982 outdatedMinor = mempty
985 outdatedCommand :: CommandUI OutdatedFlags
986 outdatedCommand = CommandUI {
987 commandName = "outdated",
988 commandSynopsis = "Check for outdated dependencies",
989 commandDescription = Just $ \_ -> wrapText $
990 "Checks for outdated dependencies in the package description file "
991 ++ "or freeze file",
992 commandNotes = Nothing,
993 commandUsage = usageFlags "outdated",
994 commandDefaultFlags = defaultOutdatedFlags,
995 commandOptions = \ _ -> [
996 optionVerbosity outdatedVerbosity
997 (\v flags -> flags { outdatedVerbosity = v })
999 ,option [] ["freeze-file"]
1000 "Act on the freeze file"
1001 outdatedFreezeFile (\v flags -> flags { outdatedFreezeFile = v })
1002 trueArg
1004 ,option [] ["new-freeze-file"]
1005 "Act on the new-style freeze file"
1006 outdatedNewFreezeFile (\v flags -> flags { outdatedNewFreezeFile = v })
1007 trueArg
1009 ,option [] ["simple-output"]
1010 "Only print names of outdated dependencies, one per line"
1011 outdatedSimpleOutput (\v flags -> flags { outdatedSimpleOutput = v })
1012 trueArg
1014 ,option [] ["exit-code"]
1015 "Exit with non-zero when there are outdated dependencies"
1016 outdatedExitCode (\v flags -> flags { outdatedExitCode = v })
1017 trueArg
1019 ,option ['q'] ["quiet"]
1020 "Don't print any output. Implies '--exit-code' and '-v0'"
1021 outdatedQuiet (\v flags -> flags { outdatedQuiet = v })
1022 trueArg
1024 ,option [] ["ignore"]
1025 "Packages to ignore"
1026 outdatedIgnore (\v flags -> flags { outdatedIgnore = v })
1027 (reqArg "PKGS" pkgNameListParser (map display))
1029 ,option [] ["minor"]
1030 "Ignore major version bumps for these packages"
1031 outdatedMinor (\v flags -> flags { outdatedMinor = v })
1032 (optArg "PKGS" ignoreMajorVersionBumpsParser
1033 (Just IgnoreMajorVersionBumpsAll) ignoreMajorVersionBumpsPrinter)
1036 where
1037 ignoreMajorVersionBumpsPrinter :: (Maybe IgnoreMajorVersionBumps)
1038 -> [Maybe String]
1039 ignoreMajorVersionBumpsPrinter Nothing = []
1040 ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsNone)= []
1041 ignoreMajorVersionBumpsPrinter (Just IgnoreMajorVersionBumpsAll) = [Nothing]
1042 ignoreMajorVersionBumpsPrinter (Just (IgnoreMajorVersionBumpsSome pkgs)) =
1043 map (Just . display) $ pkgs
1045 ignoreMajorVersionBumpsParser =
1046 (Just . IgnoreMajorVersionBumpsSome) `fmap` pkgNameListParser
1048 pkgNameListParser = readP_to_E
1049 ("Couldn't parse the list of package names: " ++)
1050 (Parse.sepBy1 parse (Parse.char ','))
1052 -- ------------------------------------------------------------
1053 -- * Update command
1054 -- ------------------------------------------------------------
1056 data UpdateFlags
1057 = UpdateFlags {
1058 updateVerbosity :: Flag Verbosity,
1059 updateIndexState :: Flag IndexState
1060 } deriving Generic
1062 defaultUpdateFlags :: UpdateFlags
1063 defaultUpdateFlags
1064 = UpdateFlags {
1065 updateVerbosity = toFlag normal,
1066 updateIndexState = toFlag IndexStateHead
1069 updateCommand :: CommandUI UpdateFlags
1070 updateCommand = CommandUI {
1071 commandName = "update",
1072 commandSynopsis = "Updates list of known packages.",
1073 commandDescription = Just $ \_ ->
1074 "For all known remote repositories, download the package list.\n",
1075 commandNotes = Just $ \_ ->
1076 relevantConfigValuesText ["remote-repo"
1077 ,"remote-repo-cache"
1078 ,"local-repo"],
1079 commandUsage = usageFlags "update",
1080 commandDefaultFlags = defaultUpdateFlags,
1081 commandOptions = \_ -> [
1082 optionVerbosity updateVerbosity (\v flags -> flags { updateVerbosity = v }),
1083 option [] ["index-state"]
1084 ("Update the source package index to its state as it existed at a previous time. " ++
1085 "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
1086 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD').")
1087 updateIndexState (\v flags -> flags { updateIndexState = v })
1088 (reqArg "STATE" (readP_to_E (const $ "index-state must be a " ++
1089 "unix-timestamps (e.g. '@1474732068'), " ++
1090 "a ISO8601 UTC timestamp " ++
1091 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
1092 (toFlag `fmap` parse))
1093 (flagToList . fmap display))
1097 -- ------------------------------------------------------------
1098 -- * Other commands
1099 -- ------------------------------------------------------------
1101 upgradeCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
1102 upgradeCommand = configureCommand {
1103 commandName = "upgrade",
1104 commandSynopsis = "(command disabled, use install instead)",
1105 commandDescription = Nothing,
1106 commandUsage = usageFlagsOrPackages "upgrade",
1107 commandDefaultFlags = (mempty, mempty, mempty, mempty),
1108 commandOptions = commandOptions installCommand
1112 cleanCommand :: CommandUI ()
1113 cleanCommand = makeCommand name shortDesc longDesc emptyFlags options
1114 where
1115 name = "clean"
1116 shortDesc = "Removes downloaded files"
1117 longDesc = Nothing
1118 emptyFlags = ()
1119 options _ = []
1122 checkCommand :: CommandUI (Flag Verbosity)
1123 checkCommand = CommandUI {
1124 commandName = "check",
1125 commandSynopsis = "Check the package for common mistakes.",
1126 commandDescription = Just $ \_ -> wrapText $
1127 "Expects a .cabal package file in the current directory.\n"
1128 ++ "\n"
1129 ++ "The checks correspond to the requirements to packages on Hackage. "
1130 ++ "If no errors and warnings are reported, Hackage will accept this "
1131 ++ "package.\n",
1132 commandNotes = Nothing,
1133 commandUsage = \pname -> "Usage: " ++ pname ++ " check\n",
1134 commandDefaultFlags = toFlag normal,
1135 commandOptions = \_ -> []
1138 formatCommand :: CommandUI (Flag Verbosity)
1139 formatCommand = CommandUI {
1140 commandName = "format",
1141 commandSynopsis = "Reformat the .cabal file using the standard style.",
1142 commandDescription = Nothing,
1143 commandNotes = Nothing,
1144 commandUsage = usageAlternatives "format" ["[FILE]"],
1145 commandDefaultFlags = toFlag normal,
1146 commandOptions = \_ -> []
1149 uninstallCommand :: CommandUI (Flag Verbosity)
1150 uninstallCommand = CommandUI {
1151 commandName = "uninstall",
1152 commandSynopsis = "Warn about 'uninstall' not being implemented.",
1153 commandDescription = Nothing,
1154 commandNotes = Nothing,
1155 commandUsage = usageAlternatives "uninstall" ["PACKAGES"],
1156 commandDefaultFlags = toFlag normal,
1157 commandOptions = \_ -> []
1160 manpageCommand :: CommandUI (Flag Verbosity)
1161 manpageCommand = CommandUI {
1162 commandName = "manpage",
1163 commandSynopsis = "Outputs manpage source.",
1164 commandDescription = Just $ \_ ->
1165 "Output manpage source to STDOUT.\n",
1166 commandNotes = Nothing,
1167 commandUsage = usageFlags "manpage",
1168 commandDefaultFlags = toFlag normal,
1169 commandOptions = \_ -> [optionVerbosity id const]
1172 runCommand :: CommandUI (BuildFlags, BuildExFlags)
1173 runCommand = CommandUI {
1174 commandName = "run",
1175 commandSynopsis = "Builds and runs an executable.",
1176 commandDescription = Just $ \pname -> wrapText $
1177 "Builds and then runs the specified executable. If no executable is "
1178 ++ "specified, but the package contains just one executable, that one "
1179 ++ "is built and executed.\n"
1180 ++ "\n"
1181 ++ "Use `" ++ pname ++ " test --show-details=streaming` to run a "
1182 ++ "test-suite and get its full output.\n",
1183 commandNotes = Just $ \pname ->
1184 "Examples:\n"
1185 ++ " " ++ pname ++ " run\n"
1186 ++ " Run the only executable in the current package;\n"
1187 ++ " " ++ pname ++ " run foo -- --fooflag\n"
1188 ++ " Works similar to `./foo --fooflag`.\n",
1189 commandUsage = usageAlternatives "run"
1190 ["[FLAGS] [EXECUTABLE] [-- EXECUTABLE_FLAGS]"],
1191 commandDefaultFlags = mempty,
1192 commandOptions =
1193 \showOrParseArgs -> liftOptions fst setFst
1194 (commandOptions parent showOrParseArgs)
1196 liftOptions snd setSnd
1197 (buildExOptions showOrParseArgs)
1199 where
1200 setFst a (_,b) = (a,b)
1201 setSnd b (a,_) = (a,b)
1203 parent = Cabal.buildCommand defaultProgramDb
1205 -- ------------------------------------------------------------
1206 -- * Report flags
1207 -- ------------------------------------------------------------
1209 data ReportFlags = ReportFlags {
1210 reportUsername :: Flag Username,
1211 reportPassword :: Flag Password,
1212 reportVerbosity :: Flag Verbosity
1213 } deriving Generic
1215 defaultReportFlags :: ReportFlags
1216 defaultReportFlags = ReportFlags {
1217 reportUsername = mempty,
1218 reportPassword = mempty,
1219 reportVerbosity = toFlag normal
1222 reportCommand :: CommandUI ReportFlags
1223 reportCommand = CommandUI {
1224 commandName = "report",
1225 commandSynopsis = "Upload build reports to a remote server.",
1226 commandDescription = Nothing,
1227 commandNotes = Just $ \_ ->
1228 "You can store your Hackage login in the ~/.cabal/config file\n",
1229 commandUsage = usageAlternatives "report" ["[FLAGS]"],
1230 commandDefaultFlags = defaultReportFlags,
1231 commandOptions = \_ ->
1232 [optionVerbosity reportVerbosity (\v flags -> flags { reportVerbosity = v })
1234 ,option ['u'] ["username"]
1235 "Hackage username."
1236 reportUsername (\v flags -> flags { reportUsername = v })
1237 (reqArg' "USERNAME" (toFlag . Username)
1238 (flagToList . fmap unUsername))
1240 ,option ['p'] ["password"]
1241 "Hackage password."
1242 reportPassword (\v flags -> flags { reportPassword = v })
1243 (reqArg' "PASSWORD" (toFlag . Password)
1244 (flagToList . fmap unPassword))
1248 instance Monoid ReportFlags where
1249 mempty = gmempty
1250 mappend = (<>)
1252 instance Semigroup ReportFlags where
1253 (<>) = gmappend
1255 -- ------------------------------------------------------------
1256 -- * Get flags
1257 -- ------------------------------------------------------------
1259 data GetFlags = GetFlags {
1260 getDestDir :: Flag FilePath,
1261 getPristine :: Flag Bool,
1262 getIndexState :: Flag IndexState,
1263 getSourceRepository :: Flag (Maybe RepoKind),
1264 getVerbosity :: Flag Verbosity
1265 } deriving Generic
1267 defaultGetFlags :: GetFlags
1268 defaultGetFlags = GetFlags {
1269 getDestDir = mempty,
1270 getPristine = mempty,
1271 getIndexState = mempty,
1272 getSourceRepository = mempty,
1273 getVerbosity = toFlag normal
1276 getCommand :: CommandUI GetFlags
1277 getCommand = CommandUI {
1278 commandName = "get",
1279 commandSynopsis = "Download/Extract a package's source code (repository).",
1280 commandDescription = Just $ \_ -> wrapText $
1281 "Creates a local copy of a package's source code. By default it gets "
1282 ++ "the source\ntarball and unpacks it in a local subdirectory. "
1283 ++ "Alternatively, with -s it will\nget the code from the source "
1284 ++ "repository specified by the package.\n",
1285 commandNotes = Just $ \pname ->
1286 "Examples:\n"
1287 ++ " " ++ pname ++ " get hlint\n"
1288 ++ " Download the latest stable version of hlint;\n"
1289 ++ " " ++ pname ++ " get lens --source-repository=head\n"
1290 ++ " Download the source repository (i.e. git clone from github).\n",
1291 commandUsage = usagePackages "get",
1292 commandDefaultFlags = defaultGetFlags,
1293 commandOptions = \_ -> [
1294 optionVerbosity getVerbosity (\v flags -> flags { getVerbosity = v })
1296 ,option "d" ["destdir"]
1297 "Where to place the package source, defaults to the current directory."
1298 getDestDir (\v flags -> flags { getDestDir = v })
1299 (reqArgFlag "PATH")
1301 ,option "s" ["source-repository"]
1302 "Copy the package's source repository (ie git clone, darcs get, etc as appropriate)."
1303 getSourceRepository (\v flags -> flags { getSourceRepository = v })
1304 (optArg "[head|this|...]" (readP_to_E (const "invalid source-repository")
1305 (fmap (toFlag . Just) parse))
1306 (Flag Nothing)
1307 (map (fmap show) . flagToList))
1309 , option [] ["index-state"]
1310 ("Use source package index state as it existed at a previous time. " ++
1311 "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
1312 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD'). " ++
1313 "This determines which package versions are available as well as " ++
1314 ".cabal file revision is selected (unless --pristine is used).")
1315 getIndexState (\v flags -> flags { getIndexState = v })
1316 (reqArg "STATE" (readP_to_E (const $ "index-state must be a " ++
1317 "unix-timestamps (e.g. '@1474732068'), " ++
1318 "a ISO8601 UTC timestamp " ++
1319 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
1320 (toFlag `fmap` parse))
1321 (flagToList . fmap display))
1323 , option [] ["pristine"]
1324 ("Unpack the original pristine tarball, rather than updating the "
1325 ++ ".cabal file with the latest revision from the package archive.")
1326 getPristine (\v flags -> flags { getPristine = v })
1327 trueArg
1331 -- 'cabal unpack' is a deprecated alias for 'cabal get'.
1332 unpackCommand :: CommandUI GetFlags
1333 unpackCommand = getCommand {
1334 commandName = "unpack",
1335 commandUsage = usagePackages "unpack"
1338 instance Monoid GetFlags where
1339 mempty = gmempty
1340 mappend = (<>)
1342 instance Semigroup GetFlags where
1343 (<>) = gmappend
1345 -- ------------------------------------------------------------
1346 -- * List flags
1347 -- ------------------------------------------------------------
1349 data ListFlags = ListFlags {
1350 listInstalled :: Flag Bool,
1351 listSimpleOutput :: Flag Bool,
1352 listVerbosity :: Flag Verbosity,
1353 listPackageDBs :: [Maybe PackageDB]
1354 } deriving Generic
1356 defaultListFlags :: ListFlags
1357 defaultListFlags = ListFlags {
1358 listInstalled = Flag False,
1359 listSimpleOutput = Flag False,
1360 listVerbosity = toFlag normal,
1361 listPackageDBs = []
1364 listCommand :: CommandUI ListFlags
1365 listCommand = CommandUI {
1366 commandName = "list",
1367 commandSynopsis = "List packages matching a search string.",
1368 commandDescription = Just $ \_ -> wrapText $
1369 "List all packages, or all packages matching one of the search"
1370 ++ " strings.\n"
1371 ++ "\n"
1372 ++ "If there is a sandbox in the current directory and "
1373 ++ "config:ignore-sandbox is False, use the sandbox package database. "
1374 ++ "Otherwise, use the package database specified with --package-db. "
1375 ++ "If not specified, use the user package database.\n",
1376 commandNotes = Just $ \pname ->
1377 "Examples:\n"
1378 ++ " " ++ pname ++ " list pandoc\n"
1379 ++ " Will find pandoc, pandoc-citeproc, pandoc-lens, ...\n",
1380 commandUsage = usageAlternatives "list" [ "[FLAGS]"
1381 , "[FLAGS] STRINGS"],
1382 commandDefaultFlags = defaultListFlags,
1383 commandOptions = \_ -> [
1384 optionVerbosity listVerbosity (\v flags -> flags { listVerbosity = v })
1386 , option [] ["installed"]
1387 "Only print installed packages"
1388 listInstalled (\v flags -> flags { listInstalled = v })
1389 trueArg
1391 , option [] ["simple-output"]
1392 "Print in a easy-to-parse format"
1393 listSimpleOutput (\v flags -> flags { listSimpleOutput = v })
1394 trueArg
1396 , option "" ["package-db"]
1397 ( "Append the given package database to the list of package"
1398 ++ " databases used (to satisfy dependencies and register into)."
1399 ++ " May be a specific file, 'global' or 'user'. The initial list"
1400 ++ " is ['global'], ['global', 'user'], or ['global', $sandbox],"
1401 ++ " depending on context. Use 'clear' to reset the list to empty."
1402 ++ " See the user guide for details.")
1403 listPackageDBs (\v flags -> flags { listPackageDBs = v })
1404 (reqArg' "DB" readPackageDbList showPackageDbList)
1409 instance Monoid ListFlags where
1410 mempty = gmempty
1411 mappend = (<>)
1413 instance Semigroup ListFlags where
1414 (<>) = gmappend
1416 -- ------------------------------------------------------------
1417 -- * Info flags
1418 -- ------------------------------------------------------------
1420 data InfoFlags = InfoFlags {
1421 infoVerbosity :: Flag Verbosity,
1422 infoPackageDBs :: [Maybe PackageDB]
1423 } deriving Generic
1425 defaultInfoFlags :: InfoFlags
1426 defaultInfoFlags = InfoFlags {
1427 infoVerbosity = toFlag normal,
1428 infoPackageDBs = []
1431 infoCommand :: CommandUI InfoFlags
1432 infoCommand = CommandUI {
1433 commandName = "info",
1434 commandSynopsis = "Display detailed information about a particular package.",
1435 commandDescription = Just $ \_ -> wrapText $
1436 "If there is a sandbox in the current directory and "
1437 ++ "config:ignore-sandbox is False, use the sandbox package database. "
1438 ++ "Otherwise, use the package database specified with --package-db. "
1439 ++ "If not specified, use the user package database.\n",
1440 commandNotes = Nothing,
1441 commandUsage = usageAlternatives "info" ["[FLAGS] PACKAGES"],
1442 commandDefaultFlags = defaultInfoFlags,
1443 commandOptions = \_ -> [
1444 optionVerbosity infoVerbosity (\v flags -> flags { infoVerbosity = v })
1446 , option "" ["package-db"]
1447 ( "Append the given package database to the list of package"
1448 ++ " databases used (to satisfy dependencies and register into)."
1449 ++ " May be a specific file, 'global' or 'user'. The initial list"
1450 ++ " is ['global'], ['global', 'user'], or ['global', $sandbox],"
1451 ++ " depending on context. Use 'clear' to reset the list to empty."
1452 ++ " See the user guide for details.")
1453 infoPackageDBs (\v flags -> flags { infoPackageDBs = v })
1454 (reqArg' "DB" readPackageDbList showPackageDbList)
1459 instance Monoid InfoFlags where
1460 mempty = gmempty
1461 mappend = (<>)
1463 instance Semigroup InfoFlags where
1464 (<>) = gmappend
1466 -- ------------------------------------------------------------
1467 -- * Install flags
1468 -- ------------------------------------------------------------
1470 -- | Install takes the same flags as configure along with a few extras.
1472 data InstallFlags = InstallFlags {
1473 installDocumentation :: Flag Bool,
1474 installHaddockIndex :: Flag PathTemplate,
1475 installDryRun :: Flag Bool,
1476 installMaxBackjumps :: Flag Int,
1477 installReorderGoals :: Flag ReorderGoals,
1478 installCountConflicts :: Flag CountConflicts,
1479 installIndependentGoals :: Flag IndependentGoals,
1480 installShadowPkgs :: Flag ShadowPkgs,
1481 installStrongFlags :: Flag StrongFlags,
1482 installAllowBootLibInstalls :: Flag AllowBootLibInstalls,
1483 installReinstall :: Flag Bool,
1484 installAvoidReinstalls :: Flag AvoidReinstalls,
1485 installOverrideReinstall :: Flag Bool,
1486 installUpgradeDeps :: Flag Bool,
1487 installOnly :: Flag Bool,
1488 installOnlyDeps :: Flag Bool,
1489 installIndexState :: Flag IndexState,
1490 installRootCmd :: Flag String,
1491 installSummaryFile :: NubList PathTemplate,
1492 installLogFile :: Flag PathTemplate,
1493 installBuildReports :: Flag ReportLevel,
1494 installReportPlanningFailure :: Flag Bool,
1495 installSymlinkBinDir :: Flag FilePath,
1496 installPerComponent :: Flag Bool,
1497 installOneShot :: Flag Bool,
1498 installNumJobs :: Flag (Maybe Int),
1499 installKeepGoing :: Flag Bool,
1500 installRunTests :: Flag Bool,
1501 installOfflineMode :: Flag Bool,
1502 -- | The cabal project file name; defaults to @cabal.project@.
1503 -- Th name itself denotes the cabal project file name, but it also
1504 -- is the base of auxiliary project files, such as
1505 -- @cabal.project.local@ and @cabal.project.freeze@ which are also
1506 -- read and written out in some cases. If the path is not found
1507 -- in the current working directory, we will successively probe
1508 -- relative to parent directories until this name is found.
1509 installProjectFileName :: Flag FilePath
1511 deriving (Eq, Generic)
1513 instance Binary InstallFlags
1515 defaultInstallFlags :: InstallFlags
1516 defaultInstallFlags = InstallFlags {
1517 installDocumentation = Flag False,
1518 installHaddockIndex = Flag docIndexFile,
1519 installDryRun = Flag False,
1520 installMaxBackjumps = Flag defaultMaxBackjumps,
1521 installReorderGoals = Flag (ReorderGoals False),
1522 installCountConflicts = Flag (CountConflicts True),
1523 installIndependentGoals= Flag (IndependentGoals False),
1524 installShadowPkgs = Flag (ShadowPkgs False),
1525 installStrongFlags = Flag (StrongFlags False),
1526 installAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
1527 installReinstall = Flag False,
1528 installAvoidReinstalls = Flag (AvoidReinstalls False),
1529 installOverrideReinstall = Flag False,
1530 installUpgradeDeps = Flag False,
1531 installOnly = Flag False,
1532 installOnlyDeps = Flag False,
1533 installIndexState = mempty,
1534 installRootCmd = mempty,
1535 installSummaryFile = mempty,
1536 installLogFile = mempty,
1537 installBuildReports = Flag NoReports,
1538 installReportPlanningFailure = Flag False,
1539 installSymlinkBinDir = mempty,
1540 installPerComponent = Flag True,
1541 installOneShot = Flag False,
1542 installNumJobs = mempty,
1543 installKeepGoing = Flag False,
1544 installRunTests = mempty,
1545 installOfflineMode = Flag False,
1546 installProjectFileName = mempty
1548 where
1549 docIndexFile = toPathTemplate ("$datadir" </> "doc"
1550 </> "$arch-$os-$compiler" </> "index.html")
1552 defaultMaxBackjumps :: Int
1553 defaultMaxBackjumps = 2000
1555 defaultSolver :: PreSolver
1556 defaultSolver = AlwaysModular
1558 allSolvers :: String
1559 allSolvers = intercalate ", " (map display ([minBound .. maxBound] :: [PreSolver]))
1561 installCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
1562 installCommand = CommandUI {
1563 commandName = "install",
1564 commandSynopsis = "Install packages.",
1565 commandUsage = usageAlternatives "install" [ "[FLAGS]"
1566 , "[FLAGS] PACKAGES"
1568 commandDescription = Just $ \_ -> wrapText $
1569 "Installs one or more packages. By default, the installed package"
1570 ++ " will be registered in the user's package database or, if a sandbox"
1571 ++ " is present in the current directory, inside the sandbox.\n"
1572 ++ "\n"
1573 ++ "If PACKAGES are specified, downloads and installs those packages."
1574 ++ " Otherwise, install the package in the current directory (and/or its"
1575 ++ " dependencies) (there must be exactly one .cabal file in the current"
1576 ++ " directory).\n"
1577 ++ "\n"
1578 ++ "When using a sandbox, the flags for `install` only affect the"
1579 ++ " current command and have no effect on future commands. (To achieve"
1580 ++ " that, `configure` must be used.)\n"
1581 ++ " In contrast, without a sandbox, the flags to `install` are saved and"
1582 ++ " affect future commands such as `build` and `repl`. See the help for"
1583 ++ " `configure` for a list of commands being affected.\n"
1584 ++ "\n"
1585 ++ "Installed executables will by default (and without a sandbox)"
1586 ++ " be put into `~/.cabal/bin/`."
1587 ++ " If you want installed executable to be available globally, make"
1588 ++ " sure that the PATH environment variable contains that directory.\n"
1589 ++ "When using a sandbox, executables will be put into"
1590 ++ " `$SANDBOX/bin/` (by default: `./.cabal-sandbox/bin/`).\n"
1591 ++ "\n"
1592 ++ "When specifying --bindir, consider also specifying --datadir;"
1593 ++ " this way the sandbox can be deleted and the executable should"
1594 ++ " continue working as long as bindir and datadir are left untouched.",
1595 commandNotes = Just $ \pname ->
1596 ( case commandNotes
1597 $ Cabal.configureCommand defaultProgramDb
1598 of Just desc -> desc pname ++ "\n"
1599 Nothing -> ""
1601 ++ "Examples:\n"
1602 ++ " " ++ pname ++ " install "
1603 ++ " Package in the current directory\n"
1604 ++ " " ++ pname ++ " install foo "
1605 ++ " Package from the hackage server\n"
1606 ++ " " ++ pname ++ " install foo-1.0 "
1607 ++ " Specific version of a package\n"
1608 ++ " " ++ pname ++ " install 'foo < 2' "
1609 ++ " Constrained package version\n"
1610 ++ " " ++ pname ++ " install haddock --bindir=$HOME/hask-bin/ --datadir=$HOME/hask-data/\n"
1611 ++ " " ++ (map (const ' ') pname)
1612 ++ " "
1613 ++ " Change installation destination\n",
1614 commandDefaultFlags = (mempty, mempty, mempty, mempty),
1615 commandOptions = \showOrParseArgs ->
1616 liftOptions get1 set1
1617 (filter ((`notElem` ["constraint", "dependency"
1618 , "exact-configuration"])
1619 . optionName) $
1620 configureOptions showOrParseArgs)
1621 ++ liftOptions get2 set2 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
1622 ++ liftOptions get3 set3 (installOptions showOrParseArgs)
1623 ++ liftOptions get4 set4 (haddockOptions showOrParseArgs)
1625 where
1626 get1 (a,_,_,_) = a; set1 a (_,b,c,d) = (a,b,c,d)
1627 get2 (_,b,_,_) = b; set2 b (a,_,c,d) = (a,b,c,d)
1628 get3 (_,_,c,_) = c; set3 c (a,b,_,d) = (a,b,c,d)
1629 get4 (_,_,_,d) = d; set4 d (a,b,c,_) = (a,b,c,d)
1631 haddockOptions :: ShowOrParseArgs -> [OptionField HaddockFlags]
1632 haddockOptions showOrParseArgs
1633 = [ opt { optionName = "haddock-" ++ name,
1634 optionDescr = [ fmapOptFlags (\(_, lflags) -> ([], map ("haddock-" ++) lflags)) descr
1635 | descr <- optionDescr opt] }
1636 | opt <- commandOptions Cabal.haddockCommand showOrParseArgs
1637 , let name = optionName opt
1638 , name `elem` ["hoogle", "html", "html-location"
1639 ,"executables", "tests", "benchmarks", "all", "internal", "css"
1640 ,"hyperlink-source", "hscolour-css"
1641 ,"contents-location", "for-hackage"]
1643 where
1644 fmapOptFlags :: (OptFlags -> OptFlags) -> OptDescr a -> OptDescr a
1645 fmapOptFlags modify (ReqArg d f p r w) = ReqArg d (modify f) p r w
1646 fmapOptFlags modify (OptArg d f p r i w) = OptArg d (modify f) p r i w
1647 fmapOptFlags modify (ChoiceOpt xs) = ChoiceOpt [(d, modify f, i, w) | (d, f, i, w) <- xs]
1648 fmapOptFlags modify (BoolOpt d f1 f2 r w) = BoolOpt d (modify f1) (modify f2) r w
1650 installOptions :: ShowOrParseArgs -> [OptionField InstallFlags]
1651 installOptions showOrParseArgs =
1652 [ option "" ["documentation"]
1653 "building of documentation"
1654 installDocumentation (\v flags -> flags { installDocumentation = v })
1655 (boolOpt [] [])
1657 , option [] ["doc-index-file"]
1658 "A central index of haddock API documentation (template cannot use $pkgid)"
1659 installHaddockIndex (\v flags -> flags { installHaddockIndex = v })
1660 (reqArg' "TEMPLATE" (toFlag.toPathTemplate)
1661 (flagToList . fmap fromPathTemplate))
1663 , option [] ["dry-run"]
1664 "Do not install anything, only print what would be installed."
1665 installDryRun (\v flags -> flags { installDryRun = v })
1666 trueArg
1667 ] ++
1669 optionSolverFlags showOrParseArgs
1670 installMaxBackjumps (\v flags -> flags { installMaxBackjumps = v })
1671 installReorderGoals (\v flags -> flags { installReorderGoals = v })
1672 installCountConflicts (\v flags -> flags { installCountConflicts = v })
1673 installIndependentGoals (\v flags -> flags { installIndependentGoals = v })
1674 installShadowPkgs (\v flags -> flags { installShadowPkgs = v })
1675 installStrongFlags (\v flags -> flags { installStrongFlags = v })
1676 installAllowBootLibInstalls (\v flags -> flags { installAllowBootLibInstalls = v }) ++
1678 [ option [] ["reinstall"]
1679 "Install even if it means installing the same version again."
1680 installReinstall (\v flags -> flags { installReinstall = v })
1681 (yesNoOpt showOrParseArgs)
1683 , option [] ["avoid-reinstalls"]
1684 "Do not select versions that would destructively overwrite installed packages."
1685 (fmap asBool . installAvoidReinstalls)
1686 (\v flags -> flags { installAvoidReinstalls = fmap AvoidReinstalls v })
1687 (yesNoOpt showOrParseArgs)
1689 , option [] ["force-reinstalls"]
1690 "Reinstall packages even if they will most likely break other installed packages."
1691 installOverrideReinstall (\v flags -> flags { installOverrideReinstall = v })
1692 (yesNoOpt showOrParseArgs)
1694 , option [] ["upgrade-dependencies"]
1695 "Pick the latest version for all dependencies, rather than trying to pick an installed version."
1696 installUpgradeDeps (\v flags -> flags { installUpgradeDeps = v })
1697 (yesNoOpt showOrParseArgs)
1699 , option [] ["only-dependencies"]
1700 "Install only the dependencies necessary to build the given packages"
1701 installOnlyDeps (\v flags -> flags { installOnlyDeps = v })
1702 (yesNoOpt showOrParseArgs)
1704 , option [] ["dependencies-only"]
1705 "A synonym for --only-dependencies"
1706 installOnlyDeps (\v flags -> flags { installOnlyDeps = v })
1707 (yesNoOpt showOrParseArgs)
1709 , option [] ["index-state"]
1710 ("Use source package index state as it existed at a previous time. " ++
1711 "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
1712 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD').")
1713 installIndexState (\v flags -> flags { installIndexState = v })
1714 (reqArg "STATE" (readP_to_E (const $ "index-state must be a " ++
1715 "unix-timestamps (e.g. '@1474732068'), " ++
1716 "a ISO8601 UTC timestamp " ++
1717 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
1718 (toFlag `fmap` parse))
1719 (flagToList . fmap display))
1721 , option [] ["root-cmd"]
1722 "(No longer supported, do not use.)"
1723 installRootCmd (\v flags -> flags { installRootCmd = v })
1724 (reqArg' "COMMAND" toFlag flagToList)
1726 , option [] ["symlink-bindir"]
1727 "Add symlinks to installed executables into this directory."
1728 installSymlinkBinDir (\v flags -> flags { installSymlinkBinDir = v })
1729 (reqArgFlag "DIR")
1731 , option [] ["build-summary"]
1732 "Save build summaries to file (name template can use $pkgid, $compiler, $os, $arch)"
1733 installSummaryFile (\v flags -> flags { installSummaryFile = v })
1734 (reqArg' "TEMPLATE" (\x -> toNubList [toPathTemplate x]) (map fromPathTemplate . fromNubList))
1736 , option [] ["build-log"]
1737 "Log all builds to file (name template can use $pkgid, $compiler, $os, $arch)"
1738 installLogFile (\v flags -> flags { installLogFile = v })
1739 (reqArg' "TEMPLATE" (toFlag.toPathTemplate)
1740 (flagToList . fmap fromPathTemplate))
1742 , option [] ["remote-build-reporting"]
1743 "Generate build reports to send to a remote server (none, anonymous or detailed)."
1744 installBuildReports (\v flags -> flags { installBuildReports = v })
1745 (reqArg "LEVEL" (readP_to_E (const $ "report level must be 'none', "
1746 ++ "'anonymous' or 'detailed'")
1747 (toFlag `fmap` parse))
1748 (flagToList . fmap display))
1750 , option [] ["report-planning-failure"]
1751 "Generate build reports when the dependency solver fails. This is used by the Hackage build bot."
1752 installReportPlanningFailure (\v flags -> flags { installReportPlanningFailure = v })
1753 trueArg
1755 , option "" ["per-component"]
1756 "Per-component builds when possible"
1757 installPerComponent (\v flags -> flags { installPerComponent = v })
1758 (boolOpt [] [])
1760 , option [] ["one-shot"]
1761 "Do not record the packages in the world file."
1762 installOneShot (\v flags -> flags { installOneShot = v })
1763 (yesNoOpt showOrParseArgs)
1765 , option [] ["run-tests"]
1766 "Run package test suites during installation."
1767 installRunTests (\v flags -> flags { installRunTests = v })
1768 trueArg
1770 , optionNumJobs
1771 installNumJobs (\v flags -> flags { installNumJobs = v })
1773 , option [] ["keep-going"]
1774 "After a build failure, continue to build other unaffected packages."
1775 installKeepGoing (\v flags -> flags { installKeepGoing = v })
1776 trueArg
1778 , option [] ["offline"]
1779 "Don't download packages from the Internet."
1780 installOfflineMode (\v flags -> flags { installOfflineMode = v })
1781 (yesNoOpt showOrParseArgs)
1783 , option [] ["project-file"]
1784 "Set the name of the cabal.project file to search for in parent directories"
1785 installProjectFileName (\v flags -> flags {installProjectFileName = v})
1786 (reqArgFlag "FILE")
1787 ] ++ case showOrParseArgs of -- TODO: remove when "cabal install"
1788 -- avoids
1789 ParseArgs ->
1790 [ option [] ["only"]
1791 "Only installs the package in the current directory."
1792 installOnly (\v flags -> flags { installOnly = v })
1793 trueArg ]
1794 _ -> []
1797 instance Monoid InstallFlags where
1798 mempty = gmempty
1799 mappend = (<>)
1801 instance Semigroup InstallFlags where
1802 (<>) = gmappend
1804 -- ------------------------------------------------------------
1805 -- * Upload flags
1806 -- ------------------------------------------------------------
1808 -- | Is this a candidate package or a package to be published?
1809 data IsCandidate = IsCandidate | IsPublished
1810 deriving Eq
1812 data UploadFlags = UploadFlags {
1813 uploadCandidate :: Flag IsCandidate,
1814 uploadDoc :: Flag Bool,
1815 uploadUsername :: Flag Username,
1816 uploadPassword :: Flag Password,
1817 uploadPasswordCmd :: Flag [String],
1818 uploadVerbosity :: Flag Verbosity
1819 } deriving Generic
1821 defaultUploadFlags :: UploadFlags
1822 defaultUploadFlags = UploadFlags {
1823 uploadCandidate = toFlag IsCandidate,
1824 uploadDoc = toFlag False,
1825 uploadUsername = mempty,
1826 uploadPassword = mempty,
1827 uploadPasswordCmd = mempty,
1828 uploadVerbosity = toFlag normal
1831 uploadCommand :: CommandUI UploadFlags
1832 uploadCommand = CommandUI {
1833 commandName = "upload",
1834 commandSynopsis = "Uploads source packages or documentation to Hackage.",
1835 commandDescription = Nothing,
1836 commandNotes = Just $ \_ ->
1837 "You can store your Hackage login in the ~/.cabal/config file\n"
1838 ++ relevantConfigValuesText ["username", "password"],
1839 commandUsage = \pname ->
1840 "Usage: " ++ pname ++ " upload [FLAGS] TARFILES\n",
1841 commandDefaultFlags = defaultUploadFlags,
1842 commandOptions = \_ ->
1843 [optionVerbosity uploadVerbosity
1844 (\v flags -> flags { uploadVerbosity = v })
1846 ,option [] ["publish"]
1847 "Publish the package instead of uploading it as a candidate."
1848 uploadCandidate (\v flags -> flags { uploadCandidate = v })
1849 (noArg (Flag IsPublished))
1851 ,option ['d'] ["documentation"]
1852 ("Upload documentation instead of a source package. "
1853 ++ "By default, this uploads documentation for a package candidate. "
1854 ++ "To upload documentation for "
1855 ++ "a published package, combine with --publish.")
1856 uploadDoc (\v flags -> flags { uploadDoc = v })
1857 trueArg
1859 ,option ['u'] ["username"]
1860 "Hackage username."
1861 uploadUsername (\v flags -> flags { uploadUsername = v })
1862 (reqArg' "USERNAME" (toFlag . Username)
1863 (flagToList . fmap unUsername))
1865 ,option ['p'] ["password"]
1866 "Hackage password."
1867 uploadPassword (\v flags -> flags { uploadPassword = v })
1868 (reqArg' "PASSWORD" (toFlag . Password)
1869 (flagToList . fmap unPassword))
1871 ,option ['P'] ["password-command"]
1872 "Command to get Hackage password."
1873 uploadPasswordCmd (\v flags -> flags { uploadPasswordCmd = v })
1874 (reqArg' "PASSWORD" (Flag . words) (fromMaybe [] . flagToMaybe))
1878 instance Monoid UploadFlags where
1879 mempty = gmempty
1880 mappend = (<>)
1882 instance Semigroup UploadFlags where
1883 (<>) = gmappend
1885 -- ------------------------------------------------------------
1886 -- * Init flags
1887 -- ------------------------------------------------------------
1889 emptyInitFlags :: IT.InitFlags
1890 emptyInitFlags = mempty
1892 defaultInitFlags :: IT.InitFlags
1893 defaultInitFlags = emptyInitFlags { IT.initVerbosity = toFlag normal }
1895 initCommand :: CommandUI IT.InitFlags
1896 initCommand = CommandUI {
1897 commandName = "init",
1898 commandSynopsis = "Create a new .cabal package file (interactively).",
1899 commandDescription = Just $ \_ -> wrapText $
1900 "Cabalise a project by creating a .cabal, Setup.hs, and "
1901 ++ "optionally a LICENSE file.\n"
1902 ++ "\n"
1903 ++ "Calling init with no arguments (recommended) uses an "
1904 ++ "interactive mode, which will try to guess as much as "
1905 ++ "possible and prompt you for the rest. Command-line "
1906 ++ "arguments are provided for scripting purposes. "
1907 ++ "If you don't want interactive mode, be sure to pass "
1908 ++ "the -n flag.\n",
1909 commandNotes = Nothing,
1910 commandUsage = \pname ->
1911 "Usage: " ++ pname ++ " init [FLAGS]\n",
1912 commandDefaultFlags = defaultInitFlags,
1913 commandOptions = \_ ->
1914 [ option ['n'] ["non-interactive"]
1915 "Non-interactive mode."
1916 IT.nonInteractive (\v flags -> flags { IT.nonInteractive = v })
1917 trueArg
1919 , option ['q'] ["quiet"]
1920 "Do not generate log messages to stdout."
1921 IT.quiet (\v flags -> flags { IT.quiet = v })
1922 trueArg
1924 , option [] ["no-comments"]
1925 "Do not generate explanatory comments in the .cabal file."
1926 IT.noComments (\v flags -> flags { IT.noComments = v })
1927 trueArg
1929 , option ['m'] ["minimal"]
1930 "Generate a minimal .cabal file, that is, do not include extra empty fields. Also implies --no-comments."
1931 IT.minimal (\v flags -> flags { IT.minimal = v })
1932 trueArg
1934 , option [] ["overwrite"]
1935 "Overwrite any existing .cabal, LICENSE, or Setup.hs files without warning."
1936 IT.overwrite (\v flags -> flags { IT.overwrite = v })
1937 trueArg
1939 , option [] ["package-dir"]
1940 "Root directory of the package (default = current directory)."
1941 IT.packageDir (\v flags -> flags { IT.packageDir = v })
1942 (reqArgFlag "DIRECTORY")
1944 , option ['p'] ["package-name"]
1945 "Name of the Cabal package to create."
1946 IT.packageName (\v flags -> flags { IT.packageName = v })
1947 (reqArg "PACKAGE" (readP_to_E ("Cannot parse package name: "++)
1948 (toFlag `fmap` parse))
1949 (flagToList . fmap display))
1951 , option [] ["version"]
1952 "Initial version of the package."
1953 IT.version (\v flags -> flags { IT.version = v })
1954 (reqArg "VERSION" (readP_to_E ("Cannot parse package version: "++)
1955 (toFlag `fmap` parse))
1956 (flagToList . fmap display))
1958 , option [] ["cabal-version"]
1959 "Required version of the Cabal library."
1960 IT.cabalVersion (\v flags -> flags { IT.cabalVersion = v })
1961 (reqArg "VERSION_RANGE" (readP_to_E ("Cannot parse Cabal version range: "++)
1962 (toFlag `fmap` parse))
1963 (flagToList . fmap display))
1965 , option ['l'] ["license"]
1966 "Project license."
1967 IT.license (\v flags -> flags { IT.license = v })
1968 (reqArg "LICENSE" (readP_to_E ("Cannot parse license: "++)
1969 (toFlag `fmap` parse))
1970 (flagToList . fmap display))
1972 , option ['a'] ["author"]
1973 "Name of the project's author."
1974 IT.author (\v flags -> flags { IT.author = v })
1975 (reqArgFlag "NAME")
1977 , option ['e'] ["email"]
1978 "Email address of the maintainer."
1979 IT.email (\v flags -> flags { IT.email = v })
1980 (reqArgFlag "EMAIL")
1982 , option ['u'] ["homepage"]
1983 "Project homepage and/or repository."
1984 IT.homepage (\v flags -> flags { IT.homepage = v })
1985 (reqArgFlag "URL")
1987 , option ['s'] ["synopsis"]
1988 "Short project synopsis."
1989 IT.synopsis (\v flags -> flags { IT.synopsis = v })
1990 (reqArgFlag "TEXT")
1992 , option ['c'] ["category"]
1993 "Project category."
1994 IT.category (\v flags -> flags { IT.category = v })
1995 (reqArg' "CATEGORY" (\s -> toFlag $ maybe (Left s) Right (readMaybe s))
1996 (flagToList . fmap (either id show)))
1998 , option ['x'] ["extra-source-file"]
1999 "Extra source file to be distributed with tarball."
2000 IT.extraSrc (\v flags -> flags { IT.extraSrc = v })
2001 (reqArg' "FILE" (Just . (:[]))
2002 (fromMaybe []))
2004 , option [] ["is-library"]
2005 "Build a library."
2006 IT.packageType (\v flags -> flags { IT.packageType = v })
2007 (noArg (Flag IT.Library))
2009 , option [] ["is-executable"]
2010 "Build an executable."
2011 IT.packageType
2012 (\v flags -> flags { IT.packageType = v })
2013 (noArg (Flag IT.Executable))
2015 , option [] ["main-is"]
2016 "Specify the main module."
2017 IT.mainIs
2018 (\v flags -> flags { IT.mainIs = v })
2019 (reqArgFlag "FILE")
2021 , option [] ["language"]
2022 "Specify the default language."
2023 IT.language
2024 (\v flags -> flags { IT.language = v })
2025 (reqArg "LANGUAGE" (readP_to_E ("Cannot parse language: "++)
2026 (toFlag `fmap` parse))
2027 (flagToList . fmap display))
2029 , option ['o'] ["expose-module"]
2030 "Export a module from the package."
2031 IT.exposedModules
2032 (\v flags -> flags { IT.exposedModules = v })
2033 (reqArg "MODULE" (readP_to_E ("Cannot parse module name: "++)
2034 ((Just . (:[])) `fmap` parse))
2035 (maybe [] (fmap display)))
2037 , option [] ["extension"]
2038 "Use a LANGUAGE extension (in the other-extensions field)."
2039 IT.otherExts
2040 (\v flags -> flags { IT.otherExts = v })
2041 (reqArg "EXTENSION" (readP_to_E ("Cannot parse extension: "++)
2042 ((Just . (:[])) `fmap` parse))
2043 (maybe [] (fmap display)))
2045 , option ['d'] ["dependency"]
2046 "Package dependency."
2047 IT.dependencies (\v flags -> flags { IT.dependencies = v })
2048 (reqArg "PACKAGE" (readP_to_E ("Cannot parse dependency: "++)
2049 ((Just . (:[])) `fmap` parse))
2050 (maybe [] (fmap display)))
2052 , option [] ["source-dir"]
2053 "Directory containing package source."
2054 IT.sourceDirs (\v flags -> flags { IT.sourceDirs = v })
2055 (reqArg' "DIR" (Just . (:[]))
2056 (fromMaybe []))
2058 , option [] ["build-tool"]
2059 "Required external build tool."
2060 IT.buildTools (\v flags -> flags { IT.buildTools = v })
2061 (reqArg' "TOOL" (Just . (:[]))
2062 (fromMaybe []))
2064 , optionVerbosity IT.initVerbosity (\v flags -> flags { IT.initVerbosity = v })
2068 -- ------------------------------------------------------------
2069 -- * SDist flags
2070 -- ------------------------------------------------------------
2072 -- | Extra flags to @sdist@ beyond runghc Setup sdist
2074 data SDistExFlags = SDistExFlags {
2075 sDistFormat :: Flag ArchiveFormat
2077 deriving (Show, Generic)
2079 data ArchiveFormat = TargzFormat | ZipFormat -- ...
2080 deriving (Show, Eq)
2082 defaultSDistExFlags :: SDistExFlags
2083 defaultSDistExFlags = SDistExFlags {
2084 sDistFormat = Flag TargzFormat
2087 sdistCommand :: CommandUI (SDistFlags, SDistExFlags)
2088 sdistCommand = Cabal.sdistCommand {
2089 commandDefaultFlags = (commandDefaultFlags Cabal.sdistCommand, defaultSDistExFlags),
2090 commandOptions = \showOrParseArgs ->
2091 liftOptions fst setFst (commandOptions Cabal.sdistCommand showOrParseArgs)
2092 ++ liftOptions snd setSnd sdistExOptions
2094 where
2095 setFst a (_,b) = (a,b)
2096 setSnd b (a,_) = (a,b)
2098 sdistExOptions =
2099 [option [] ["archive-format"] "archive-format"
2100 sDistFormat (\v flags -> flags { sDistFormat = v })
2101 (choiceOpt
2102 [ (Flag TargzFormat, ([], ["targz"]),
2103 "Produce a '.tar.gz' format archive (default and required for uploading to hackage)")
2104 , (Flag ZipFormat, ([], ["zip"]),
2105 "Produce a '.zip' format archive")
2109 instance Monoid SDistExFlags where
2110 mempty = gmempty
2111 mappend = (<>)
2113 instance Semigroup SDistExFlags where
2114 (<>) = gmappend
2116 -- ------------------------------------------------------------
2117 -- * Win32SelfUpgrade flags
2118 -- ------------------------------------------------------------
2120 data Win32SelfUpgradeFlags = Win32SelfUpgradeFlags {
2121 win32SelfUpgradeVerbosity :: Flag Verbosity
2122 } deriving Generic
2124 defaultWin32SelfUpgradeFlags :: Win32SelfUpgradeFlags
2125 defaultWin32SelfUpgradeFlags = Win32SelfUpgradeFlags {
2126 win32SelfUpgradeVerbosity = toFlag normal
2129 win32SelfUpgradeCommand :: CommandUI Win32SelfUpgradeFlags
2130 win32SelfUpgradeCommand = CommandUI {
2131 commandName = "win32selfupgrade",
2132 commandSynopsis = "Self-upgrade the executable on Windows",
2133 commandDescription = Nothing,
2134 commandNotes = Nothing,
2135 commandUsage = \pname ->
2136 "Usage: " ++ pname ++ " win32selfupgrade PID PATH\n",
2137 commandDefaultFlags = defaultWin32SelfUpgradeFlags,
2138 commandOptions = \_ ->
2139 [optionVerbosity win32SelfUpgradeVerbosity
2140 (\v flags -> flags { win32SelfUpgradeVerbosity = v})
2144 instance Monoid Win32SelfUpgradeFlags where
2145 mempty = gmempty
2146 mappend = (<>)
2148 instance Semigroup Win32SelfUpgradeFlags where
2149 (<>) = gmappend
2151 -- ------------------------------------------------------------
2152 -- * ActAsSetup flags
2153 -- ------------------------------------------------------------
2155 data ActAsSetupFlags = ActAsSetupFlags {
2156 actAsSetupBuildType :: Flag BuildType
2157 } deriving Generic
2159 defaultActAsSetupFlags :: ActAsSetupFlags
2160 defaultActAsSetupFlags = ActAsSetupFlags {
2161 actAsSetupBuildType = toFlag Simple
2164 actAsSetupCommand :: CommandUI ActAsSetupFlags
2165 actAsSetupCommand = CommandUI {
2166 commandName = "act-as-setup",
2167 commandSynopsis = "Run as-if this was a Setup.hs",
2168 commandDescription = Nothing,
2169 commandNotes = Nothing,
2170 commandUsage = \pname ->
2171 "Usage: " ++ pname ++ " act-as-setup\n",
2172 commandDefaultFlags = defaultActAsSetupFlags,
2173 commandOptions = \_ ->
2174 [option "" ["build-type"]
2175 "Use the given build type."
2176 actAsSetupBuildType (\v flags -> flags { actAsSetupBuildType = v })
2177 (reqArg "BUILD-TYPE" (readP_to_E ("Cannot parse build type: "++)
2178 (fmap toFlag parse))
2179 (map display . flagToList))
2183 instance Monoid ActAsSetupFlags where
2184 mempty = gmempty
2185 mappend = (<>)
2187 instance Semigroup ActAsSetupFlags where
2188 (<>) = gmappend
2190 -- ------------------------------------------------------------
2191 -- * Sandbox-related flags
2192 -- ------------------------------------------------------------
2194 data SandboxFlags = SandboxFlags {
2195 sandboxVerbosity :: Flag Verbosity,
2196 sandboxSnapshot :: Flag Bool, -- FIXME: this should be an 'add-source'-only
2197 -- flag.
2198 sandboxLocation :: Flag FilePath
2199 } deriving Generic
2201 defaultSandboxLocation :: FilePath
2202 defaultSandboxLocation = ".cabal-sandbox"
2204 defaultSandboxFlags :: SandboxFlags
2205 defaultSandboxFlags = SandboxFlags {
2206 sandboxVerbosity = toFlag normal,
2207 sandboxSnapshot = toFlag False,
2208 sandboxLocation = toFlag defaultSandboxLocation
2211 sandboxCommand :: CommandUI SandboxFlags
2212 sandboxCommand = CommandUI {
2213 commandName = "sandbox",
2214 commandSynopsis = "Create/modify/delete a sandbox.",
2215 commandDescription = Just $ \pname -> concat
2216 [ paragraph $ "Sandboxes are isolated package databases that can be used"
2217 ++ " to prevent dependency conflicts that arise when many different"
2218 ++ " packages are installed in the same database (i.e. the user's"
2219 ++ " database in the home directory)."
2220 , paragraph $ "A sandbox in the current directory (created by"
2221 ++ " `sandbox init`) will be used instead of the user's database for"
2222 ++ " commands such as `install` and `build`. Note that (a directly"
2223 ++ " invoked) GHC will not automatically be aware of sandboxes;"
2224 ++ " only if called via appropriate " ++ pname
2225 ++ " commands, e.g. `repl`, `build`, `exec`."
2226 , paragraph $ "Currently, " ++ pname ++ " will not search for a sandbox"
2227 ++ " in folders above the current one, so cabal will not see the sandbox"
2228 ++ " if you are in a subfolder of a sandbox."
2229 , paragraph "Subcommands:"
2230 , headLine "init:"
2231 , indentParagraph $ "Initialize a sandbox in the current directory."
2232 ++ " An existing package database will not be modified, but settings"
2233 ++ " (such as the location of the database) can be modified this way."
2234 , headLine "delete:"
2235 , indentParagraph $ "Remove the sandbox; deleting all the packages"
2236 ++ " installed inside."
2237 , headLine "add-source:"
2238 , indentParagraph $ "Make one or more local packages available in the"
2239 ++ " sandbox. PATHS may be relative or absolute."
2240 ++ " Typical usecase is when you need"
2241 ++ " to make a (temporary) modification to a dependency: You download"
2242 ++ " the package into a different directory, make the modification,"
2243 ++ " and add that directory to the sandbox with `add-source`."
2244 , indentParagraph $ "Unless given `--snapshot`, any add-source'd"
2245 ++ " dependency that was modified since the last build will be"
2246 ++ " re-installed automatically."
2247 , headLine "delete-source:"
2248 , indentParagraph $ "Remove an add-source dependency; however, this will"
2249 ++ " not delete the package(s) that have been installed in the sandbox"
2250 ++ " from this dependency. You can either unregister the package(s) via"
2251 ++ " `" ++ pname ++ " sandbox hc-pkg unregister` or re-create the"
2252 ++ " sandbox (`sandbox delete; sandbox init`)."
2253 , headLine "list-sources:"
2254 , indentParagraph $ "List the directories of local packages made"
2255 ++ " available via `" ++ pname ++ " add-source`."
2256 , headLine "hc-pkg:"
2257 , indentParagraph $ "Similar to `ghc-pkg`, but for the sandbox package"
2258 ++ " database. Can be used to list specific/all packages that are"
2259 ++ " installed in the sandbox. For subcommands, see the help for"
2260 ++ " ghc-pkg. Affected by the compiler version specified by `configure`."
2262 commandNotes = Just $ \pname ->
2263 relevantConfigValuesText ["require-sandbox"
2264 ,"ignore-sandbox"]
2265 ++ "\n"
2266 ++ "Examples:\n"
2267 ++ " Set up a sandbox with one local dependency, located at ../foo:\n"
2268 ++ " " ++ pname ++ " sandbox init\n"
2269 ++ " " ++ pname ++ " sandbox add-source ../foo\n"
2270 ++ " " ++ pname ++ " install --only-dependencies\n"
2271 ++ " Reset the sandbox:\n"
2272 ++ " " ++ pname ++ " sandbox delete\n"
2273 ++ " " ++ pname ++ " sandbox init\n"
2274 ++ " " ++ pname ++ " install --only-dependencies\n"
2275 ++ " List the packages in the sandbox:\n"
2276 ++ " " ++ pname ++ " sandbox hc-pkg list\n"
2277 ++ " Unregister the `broken` package from the sandbox:\n"
2278 ++ " " ++ pname ++ " sandbox hc-pkg -- --force unregister broken\n",
2279 commandUsage = usageAlternatives "sandbox"
2280 [ "init [FLAGS]"
2281 , "delete [FLAGS]"
2282 , "add-source [FLAGS] PATHS"
2283 , "delete-source [FLAGS] PATHS"
2284 , "list-sources [FLAGS]"
2285 , "hc-pkg [FLAGS] [--] COMMAND [--] [ARGS]"
2288 commandDefaultFlags = defaultSandboxFlags,
2289 commandOptions = \_ ->
2290 [ optionVerbosity sandboxVerbosity
2291 (\v flags -> flags { sandboxVerbosity = v })
2293 , option [] ["snapshot"]
2294 "Take a snapshot instead of creating a link (only applies to 'add-source')"
2295 sandboxSnapshot (\v flags -> flags { sandboxSnapshot = v })
2296 trueArg
2298 , option [] ["sandbox"]
2299 "Sandbox location (default: './.cabal-sandbox')."
2300 sandboxLocation (\v flags -> flags { sandboxLocation = v })
2301 (reqArgFlag "DIR")
2305 instance Monoid SandboxFlags where
2306 mempty = gmempty
2307 mappend = (<>)
2309 instance Semigroup SandboxFlags where
2310 (<>) = gmappend
2312 -- ------------------------------------------------------------
2313 -- * Exec Flags
2314 -- ------------------------------------------------------------
2316 data ExecFlags = ExecFlags {
2317 execVerbosity :: Flag Verbosity,
2318 execDistPref :: Flag FilePath
2319 } deriving Generic
2321 defaultExecFlags :: ExecFlags
2322 defaultExecFlags = ExecFlags {
2323 execVerbosity = toFlag normal,
2324 execDistPref = NoFlag
2327 execCommand :: CommandUI ExecFlags
2328 execCommand = CommandUI {
2329 commandName = "exec",
2330 commandSynopsis = "Give a command access to the sandbox package repository.",
2331 commandDescription = Just $ \pname -> wrapText $
2332 -- TODO: this is too GHC-focused for my liking..
2333 "A directly invoked GHC will not automatically be aware of any"
2334 ++ " sandboxes: the GHC_PACKAGE_PATH environment variable controls what"
2335 ++ " GHC uses. `" ++ pname ++ " exec` can be used to modify this variable:"
2336 ++ " COMMAND will be executed in a modified environment and thereby uses"
2337 ++ " the sandbox package database.\n"
2338 ++ "\n"
2339 ++ "If there is no sandbox, behaves as identity (executing COMMAND).\n"
2340 ++ "\n"
2341 ++ "Note that other " ++ pname ++ " commands change the environment"
2342 ++ " variable appropriately already, so there is no need to wrap those"
2343 ++ " in `" ++ pname ++ " exec`. But with `" ++ pname ++ " exec`, the user"
2344 ++ " has more control and can, for example, execute custom scripts which"
2345 ++ " indirectly execute GHC.\n"
2346 ++ "\n"
2347 ++ "Note that `" ++ pname ++ " repl` is different from `" ++ pname
2348 ++ " exec -- ghci` as the latter will not forward any additional flags"
2349 ++ " being defined in the local package to ghci.\n"
2350 ++ "\n"
2351 ++ "See `" ++ pname ++ " sandbox`.\n",
2352 commandNotes = Just $ \pname ->
2353 "Examples:\n"
2354 ++ " " ++ pname ++ " exec -- ghci -Wall\n"
2355 ++ " Start a repl session with sandbox packages and all warnings;\n"
2356 ++ " " ++ pname ++ " exec gitit -- -f gitit.cnf\n"
2357 ++ " Give gitit access to the sandbox packages, and pass it a flag;\n"
2358 ++ " " ++ pname ++ " exec runghc Foo.hs\n"
2359 ++ " Execute runghc on Foo.hs with runghc configured to use the\n"
2360 ++ " sandbox package database (if a sandbox is being used).\n",
2361 commandUsage = \pname ->
2362 "Usage: " ++ pname ++ " exec [FLAGS] [--] COMMAND [--] [ARGS]\n",
2364 commandDefaultFlags = defaultExecFlags,
2365 commandOptions = \showOrParseArgs ->
2366 [ optionVerbosity execVerbosity
2367 (\v flags -> flags { execVerbosity = v })
2368 , Cabal.optionDistPref
2369 execDistPref (\d flags -> flags { execDistPref = d })
2370 showOrParseArgs
2374 instance Monoid ExecFlags where
2375 mempty = gmempty
2376 mappend = (<>)
2378 instance Semigroup ExecFlags where
2379 (<>) = gmappend
2381 -- ------------------------------------------------------------
2382 -- * UserConfig flags
2383 -- ------------------------------------------------------------
2385 data UserConfigFlags = UserConfigFlags {
2386 userConfigVerbosity :: Flag Verbosity,
2387 userConfigForce :: Flag Bool
2388 } deriving Generic
2390 instance Monoid UserConfigFlags where
2391 mempty = UserConfigFlags {
2392 userConfigVerbosity = toFlag normal,
2393 userConfigForce = toFlag False
2395 mappend = (<>)
2397 instance Semigroup UserConfigFlags where
2398 (<>) = gmappend
2400 userConfigCommand :: CommandUI UserConfigFlags
2401 userConfigCommand = CommandUI {
2402 commandName = "user-config",
2403 commandSynopsis = "Display and update the user's global cabal configuration.",
2404 commandDescription = Just $ \_ -> wrapText $
2405 "When upgrading cabal, the set of configuration keys and their default"
2406 ++ " values may change. This command provides means to merge the existing"
2407 ++ " config in ~/.cabal/config"
2408 ++ " (i.e. all bindings that are actually defined and not commented out)"
2409 ++ " and the default config of the new version.\n"
2410 ++ "\n"
2411 ++ "init: Creates a new config file at either ~/.cabal/config or as"
2412 ++ " specified by --config-file, if given. An existing file won't be "
2413 ++ " overwritten unless -f or --force is given.\n"
2414 ++ "diff: Shows a pseudo-diff of the user's ~/.cabal/config file and"
2415 ++ " the default configuration that would be created by cabal if the"
2416 ++ " config file did not exist.\n"
2417 ++ "update: Applies the pseudo-diff to the configuration that would be"
2418 ++ " created by default, and write the result back to ~/.cabal/config.",
2420 commandNotes = Nothing,
2421 commandUsage = usageAlternatives "user-config" ["init", "diff", "update"],
2422 commandDefaultFlags = mempty,
2423 commandOptions = \ _ -> [
2424 optionVerbosity userConfigVerbosity (\v flags -> flags { userConfigVerbosity = v })
2425 , option ['f'] ["force"]
2426 "Overwrite the config file if it already exists."
2427 userConfigForce (\v flags -> flags { userConfigForce = v })
2428 trueArg
2432 -- ------------------------------------------------------------
2433 -- * GetOpt Utils
2434 -- ------------------------------------------------------------
2436 reqArgFlag :: ArgPlaceHolder ->
2437 MkOptDescr (b -> Flag String) (Flag String -> b -> b) b
2438 reqArgFlag ad = reqArg ad (succeedReadE Flag) flagToList
2440 liftOptions :: (b -> a) -> (a -> b -> b)
2441 -> [OptionField a] -> [OptionField b]
2442 liftOptions get set = map (liftOption get set)
2444 yesNoOpt :: ShowOrParseArgs -> MkOptDescr (b -> Flag Bool) (Flag Bool -> b -> b) b
2445 yesNoOpt ShowArgs sf lf = trueArg sf lf
2446 yesNoOpt _ sf lf = Command.boolOpt' flagToMaybe Flag (sf, lf) ([], map ("no-" ++) lf) sf lf
2448 optionSolver :: (flags -> Flag PreSolver)
2449 -> (Flag PreSolver -> flags -> flags)
2450 -> OptionField flags
2451 optionSolver get set =
2452 option [] ["solver"]
2453 ("Select dependency solver to use (default: " ++ display defaultSolver ++ "). Choices: " ++ allSolvers ++ ".")
2454 get set
2455 (reqArg "SOLVER" (readP_to_E (const $ "solver must be one of: " ++ allSolvers)
2456 (toFlag `fmap` parse))
2457 (flagToList . fmap display))
2459 optionSolverFlags :: ShowOrParseArgs
2460 -> (flags -> Flag Int ) -> (Flag Int -> flags -> flags)
2461 -> (flags -> Flag ReorderGoals) -> (Flag ReorderGoals -> flags -> flags)
2462 -> (flags -> Flag CountConflicts) -> (Flag CountConflicts -> flags -> flags)
2463 -> (flags -> Flag IndependentGoals) -> (Flag IndependentGoals -> flags -> flags)
2464 -> (flags -> Flag ShadowPkgs) -> (Flag ShadowPkgs -> flags -> flags)
2465 -> (flags -> Flag StrongFlags) -> (Flag StrongFlags -> flags -> flags)
2466 -> (flags -> Flag AllowBootLibInstalls) -> (Flag AllowBootLibInstalls -> flags -> flags)
2467 -> [OptionField flags]
2468 optionSolverFlags showOrParseArgs getmbj setmbj getrg setrg getcc setcc getig setig
2469 getsip setsip getstrfl setstrfl getib setib =
2470 [ option [] ["max-backjumps"]
2471 ("Maximum number of backjumps allowed while solving (default: " ++ show defaultMaxBackjumps ++ "). Use a negative number to enable unlimited backtracking. Use 0 to disable backtracking completely.")
2472 getmbj setmbj
2473 (reqArg "NUM" (readP_to_E ("Cannot parse number: "++) (fmap toFlag parse))
2474 (map show . flagToList))
2475 , option [] ["reorder-goals"]
2476 "Try to reorder goals according to certain heuristics. Slows things down on average, but may make backtracking faster for some packages."
2477 (fmap asBool . getrg)
2478 (setrg . fmap ReorderGoals)
2479 (yesNoOpt showOrParseArgs)
2480 , option [] ["count-conflicts"]
2481 "Try to speed up solving by preferring goals that are involved in a lot of conflicts (default)."
2482 (fmap asBool . getcc)
2483 (setcc . fmap CountConflicts)
2484 (yesNoOpt showOrParseArgs)
2485 , option [] ["independent-goals"]
2486 "Treat several goals on the command line as independent. If several goals depend on the same package, different versions can be chosen."
2487 (fmap asBool . getig)
2488 (setig . fmap IndependentGoals)
2489 (yesNoOpt showOrParseArgs)
2490 , option [] ["shadow-installed-packages"]
2491 "If multiple package instances of the same version are installed, treat all but one as shadowed."
2492 (fmap asBool . getsip)
2493 (setsip . fmap ShadowPkgs)
2494 (yesNoOpt showOrParseArgs)
2495 , option [] ["strong-flags"]
2496 "Do not defer flag choices (this used to be the default in cabal-install <= 1.20)."
2497 (fmap asBool . getstrfl)
2498 (setstrfl . fmap StrongFlags)
2499 (yesNoOpt showOrParseArgs)
2500 , option [] ["allow-boot-library-installs"]
2501 "Allow cabal to install base, ghc-prim, integer-simple, integer-gmp, and template-haskell."
2502 (fmap asBool . getib)
2503 (setib . fmap AllowBootLibInstalls)
2504 (yesNoOpt showOrParseArgs)
2507 usageFlagsOrPackages :: String -> String -> String
2508 usageFlagsOrPackages name pname =
2509 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS]\n"
2510 ++ " or: " ++ pname ++ " " ++ name ++ " [PACKAGES]\n"
2512 usagePackages :: String -> String -> String
2513 usagePackages name pname =
2514 "Usage: " ++ pname ++ " " ++ name ++ " [PACKAGES]\n"
2516 usageFlags :: String -> String -> String
2517 usageFlags name pname =
2518 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS]\n"
2520 --TODO: do we want to allow per-package flags?
2521 parsePackageArgs :: [String] -> Either String [Dependency]
2522 parsePackageArgs = parsePkgArgs []
2523 where
2524 parsePkgArgs ds [] = Right (reverse ds)
2525 parsePkgArgs ds (arg:args) =
2526 case readPToMaybe parseDependencyOrPackageId arg of
2527 Just dep -> parsePkgArgs (dep:ds) args
2528 Nothing -> Left $
2529 show arg ++ " is not valid syntax for a package name or"
2530 ++ " package dependency."
2532 parseDependencyOrPackageId :: Parse.ReadP r Dependency
2533 parseDependencyOrPackageId = parse Parse.+++ liftM pkgidToDependency parse
2534 where
2535 pkgidToDependency :: PackageIdentifier -> Dependency
2536 pkgidToDependency p = case packageVersion p of
2537 v | v == nullVersion -> Dependency (packageName p) anyVersion
2538 | otherwise -> Dependency (packageName p) (thisVersion v)
2540 showRepo :: RemoteRepo -> String
2541 showRepo repo = remoteRepoName repo ++ ":"
2542 ++ uriToString id (remoteRepoURI repo) []
2544 readRepo :: String -> Maybe RemoteRepo
2545 readRepo = readPToMaybe parseRepo
2547 parseRepo :: Parse.ReadP r RemoteRepo
2548 parseRepo = do
2549 name <- Parse.munch1 (\c -> isAlphaNum c || c `elem` "_-.")
2550 _ <- Parse.char ':'
2551 uriStr <- Parse.munch1 (\c -> isAlphaNum c || c `elem` "+-=._/*()@'$:;&!?~")
2552 uri <- maybe Parse.pfail return (parseAbsoluteURI uriStr)
2553 return RemoteRepo {
2554 remoteRepoName = name,
2555 remoteRepoURI = uri,
2556 remoteRepoSecure = Nothing,
2557 remoteRepoRootKeys = [],
2558 remoteRepoKeyThreshold = 0,
2559 remoteRepoShouldTryHttps = False
2562 -- ------------------------------------------------------------
2563 -- * Helpers for Documentation
2564 -- ------------------------------------------------------------
2566 headLine :: String -> String
2567 headLine = unlines
2568 . map unwords
2569 . wrapLine 79
2570 . words
2572 paragraph :: String -> String
2573 paragraph = (++"\n")
2574 . unlines
2575 . map unwords
2576 . wrapLine 79
2577 . words
2579 indentParagraph :: String -> String
2580 indentParagraph = unlines
2581 . (flip (++)) [""]
2582 . map ((" "++).unwords)
2583 . wrapLine 77
2584 . words
2586 relevantConfigValuesText :: [String] -> String
2587 relevantConfigValuesText vs =
2588 "Relevant global configuration keys:\n"
2589 ++ concat [" " ++ v ++ "\n" |v <- vs]