Merge pull request #10593 from cabalism/typo/prexif-reseved
[cabal.git] / cabal-install / src / Distribution / Client / NixStyleOptions.hs
blobff2a010ba1acd30824ee7325683c99217145ea25
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 , updNixStyleCommonSetupFlags
12 ) where
14 import Distribution.Client.Compat.Prelude
15 import Prelude ()
17 import Distribution.Simple.Command (OptionField (..), ShowOrParseArgs)
18 import Distribution.Simple.Setup
19 ( BenchmarkFlags (benchmarkCommonFlags)
20 , CommonSetupFlags (..)
21 , HaddockFlags (..)
22 , TestFlags (testCommonFlags)
24 import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..))
26 import Distribution.Client.ProjectFlags
27 ( ProjectFlags (..)
28 , defaultProjectFlags
29 , projectFlagsOptions
31 import Distribution.Client.Setup
32 ( ConfigExFlags
33 , ConfigFlags (..)
34 , InstallFlags (..)
35 , benchmarkOptions
36 , configureExOptions
37 , configureOptions
38 , haddockOptions
39 , installOptions
40 , liftOptions
41 , testOptions
44 data NixStyleFlags a = NixStyleFlags
45 { configFlags :: ConfigFlags
46 , configExFlags :: ConfigExFlags
47 , installFlags :: InstallFlags
48 , haddockFlags :: HaddockFlags
49 , testFlags :: TestFlags
50 , benchmarkFlags :: BenchmarkFlags
51 , projectFlags :: ProjectFlags
52 , extraFlags :: a
55 nixStyleOptions
56 :: (ShowOrParseArgs -> [OptionField a])
57 -> ShowOrParseArgs
58 -> [OptionField (NixStyleFlags a)]
59 nixStyleOptions commandOptions showOrParseArgs =
60 liftOptions
61 configFlags
62 set1
63 -- Note: [Hidden Flags]
64 -- We reuse the configure options from v1 commands which on their turn
65 -- reuse the ones from Cabal) but we hide some of them in v2 commands.
66 ( filter
67 ( ( `notElem`
68 [ "cabal-file"
69 , "constraint"
70 , "dependency"
71 , "promised-dependency"
72 , "exact-configuration"
75 . optionName
77 $ configureOptions showOrParseArgs
79 ++ liftOptions
80 configExFlags
81 set2
82 ( configureExOptions
83 showOrParseArgs
84 ConstraintSourceCommandlineFlag
86 ++ liftOptions
87 installFlags
88 set3
89 -- hide "target-package-db" and "symlink-bindir" flags from the
90 -- install options.
91 -- "symlink-bindir" is obsoleted by "installdir" in ClientInstallFlags
92 ( filter
93 ( (`notElem` ["target-package-db", "symlink-bindir"])
94 . optionName
96 $ installOptions showOrParseArgs
98 ++ liftOptions
99 haddockFlags
100 set4
101 -- hide "verbose" and "builddir" flags from the
102 -- haddock options.
103 ( filter
104 ( (`notElem` ["v", "verbose", "builddir"])
105 . optionName
107 $ haddockOptions showOrParseArgs
109 ++ liftOptions testFlags set5 (testOptions showOrParseArgs)
110 ++ liftOptions benchmarkFlags set6 (benchmarkOptions showOrParseArgs)
111 ++ liftOptions projectFlags set7 (projectFlagsOptions showOrParseArgs)
112 ++ liftOptions extraFlags set8 (commandOptions showOrParseArgs)
113 where
114 set1 x flags = flags{configFlags = x}
115 set2 x flags = flags{configExFlags = x}
116 set3 x flags = flags{installFlags = x}
117 set4 x flags = flags{haddockFlags = x}
118 set5 x flags = flags{testFlags = x}
119 set6 x flags = flags{benchmarkFlags = x}
120 set7 x flags = flags{projectFlags = x}
121 set8 x flags = flags{extraFlags = x}
123 defaultNixStyleFlags :: a -> NixStyleFlags a
124 defaultNixStyleFlags x =
125 NixStyleFlags
126 { configFlags = mempty
127 , configExFlags = mempty
128 , installFlags = mempty
129 , haddockFlags = mempty
130 , testFlags = mempty
131 , benchmarkFlags = mempty
132 , projectFlags = defaultProjectFlags
133 , extraFlags = x
136 updNixStyleCommonSetupFlags
137 :: (CommonSetupFlags -> CommonSetupFlags)
138 -> NixStyleFlags a
139 -> NixStyleFlags a
140 updNixStyleCommonSetupFlags setFlag nixFlags =
141 nixFlags
142 { configFlags =
143 let flags = configFlags nixFlags
144 common = configCommonFlags flags
145 in flags{configCommonFlags = setFlag common}
146 , haddockFlags =
147 let flags = haddockFlags nixFlags
148 common = haddockCommonFlags flags
149 in flags{haddockCommonFlags = setFlag common}
150 , testFlags =
151 let flags = testFlags nixFlags
152 common = testCommonFlags flags
153 in flags{testCommonFlags = setFlag common}
154 , benchmarkFlags =
155 let flags = benchmarkFlags nixFlags
156 common = benchmarkCommonFlags flags
157 in flags{benchmarkCommonFlags = setFlag common}