Add “Ignore warning” option to cabal check
[cabal.git] / cabal-install / src / Distribution / Client / NixStyleOptions.hs
blob7a047774b2bf50b546f866c05b3e3823adccc2f6
1 {-# LANGUAGE StandaloneDeriving #-}
3 -- | Command line options for nix-style / v2 commands.
4 --
5 -- The commands take a lot of the same options, which affect how install plan
6 -- is constructed.
7 module Distribution.Client.NixStyleOptions
8 ( NixStyleFlags (..)
9 , nixStyleOptions
10 , defaultNixStyleFlags
11 ) where
13 import Distribution.Client.Compat.Prelude
14 import Prelude ()
16 import Distribution.Simple.Command (OptionField (..), ShowOrParseArgs)
17 import Distribution.Simple.Setup (BenchmarkFlags, HaddockFlags, TestFlags)
18 import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..))
20 import Distribution.Client.ProjectFlags
21 ( ProjectFlags (..)
22 , defaultProjectFlags
23 , projectFlagsOptions
25 import Distribution.Client.Setup
26 ( ConfigExFlags
27 , ConfigFlags (..)
28 , InstallFlags (..)
29 , benchmarkOptions
30 , configureExOptions
31 , configureOptions
32 , haddockOptions
33 , installOptions
34 , liftOptions
35 , testOptions
38 data NixStyleFlags a = NixStyleFlags
39 { configFlags :: ConfigFlags
40 , configExFlags :: ConfigExFlags
41 , installFlags :: InstallFlags
42 , haddockFlags :: HaddockFlags
43 , testFlags :: TestFlags
44 , benchmarkFlags :: BenchmarkFlags
45 , projectFlags :: ProjectFlags
46 , extraFlags :: a
49 nixStyleOptions
50 :: (ShowOrParseArgs -> [OptionField a])
51 -> ShowOrParseArgs
52 -> [OptionField (NixStyleFlags a)]
53 nixStyleOptions commandOptions showOrParseArgs =
54 liftOptions
55 configFlags
56 set1
57 -- Note: [Hidden Flags]
58 -- We reuse the configure options from v1 commands which on their turn
59 -- reuse the ones from Cabal) but we hide some of them in v2 commands.
60 ( filter
61 ( ( `notElem`
62 [ "cabal-file"
63 , "constraint"
64 , "dependency"
65 , "promised-dependency"
66 , "exact-configuration"
69 . optionName
71 $ configureOptions showOrParseArgs
73 ++ liftOptions
74 configExFlags
75 set2
76 ( configureExOptions
77 showOrParseArgs
78 ConstraintSourceCommandlineFlag
80 ++ liftOptions
81 installFlags
82 set3
83 -- hide "target-package-db" and "symlink-bindir" flags from the
84 -- install options.
85 -- "symlink-bindir" is obsoleted by "installdir" in ClientInstallFlags
86 ( filter
87 ( (`notElem` ["target-package-db", "symlink-bindir"])
88 . optionName
90 $ installOptions showOrParseArgs
92 ++ liftOptions
93 haddockFlags
94 set4
95 -- hide "verbose" and "builddir" flags from the
96 -- haddock options.
97 ( filter
98 ( (`notElem` ["v", "verbose", "builddir"])
99 . optionName
101 $ haddockOptions showOrParseArgs
103 ++ liftOptions testFlags set5 (testOptions showOrParseArgs)
104 ++ liftOptions benchmarkFlags set6 (benchmarkOptions showOrParseArgs)
105 ++ liftOptions projectFlags set7 (projectFlagsOptions showOrParseArgs)
106 ++ liftOptions extraFlags set8 (commandOptions showOrParseArgs)
107 where
108 set1 x flags = flags{configFlags = x}
109 set2 x flags = flags{configExFlags = x}
110 set3 x flags = flags{installFlags = x}
111 set4 x flags = flags{haddockFlags = x}
112 set5 x flags = flags{testFlags = x}
113 set6 x flags = flags{benchmarkFlags = x}
114 set7 x flags = flags{projectFlags = x}
115 set8 x flags = flags{extraFlags = x}
117 defaultNixStyleFlags :: a -> NixStyleFlags a
118 defaultNixStyleFlags x =
119 NixStyleFlags
120 { configFlags = mempty
121 , configExFlags = mempty
122 , installFlags = mempty
123 , haddockFlags = mempty
124 , testFlags = mempty
125 , benchmarkFlags = mempty
126 , projectFlags = defaultProjectFlags
127 , extraFlags = x