cabal init -i should sanitize suggested package name (fix #8404) (#8561)
[cabal.git] / cabal-install / src / Distribution / Client / NixStyleOptions.hs
blob3fbcada5679573a826ffe99746dd077a2b3a671e
1 -- | Command line options for nix-style / v2 commands.
2 --
3 -- The commands take a lot of the same options, which affect how install plan
4 -- is constructed.
5 module Distribution.Client.NixStyleOptions (
6 NixStyleFlags (..),
7 nixStyleOptions,
8 defaultNixStyleFlags,
9 ) where
11 import Distribution.Client.Compat.Prelude
12 import Prelude ()
14 import Distribution.Simple.Command (OptionField (..), ShowOrParseArgs)
15 import Distribution.Simple.Setup (BenchmarkFlags, HaddockFlags, TestFlags)
16 import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..))
18 import Distribution.Client.ProjectFlags
19 (ProjectFlags (..), defaultProjectFlags, projectFlagsOptions)
20 import Distribution.Client.Setup
21 (ConfigExFlags, ConfigFlags (..), InstallFlags (..), benchmarkOptions, configureExOptions,
22 configureOptions, haddockOptions, installOptions, liftOptions, testOptions)
24 data NixStyleFlags a = NixStyleFlags
25 { configFlags :: ConfigFlags
26 , configExFlags :: ConfigExFlags
27 , installFlags :: InstallFlags
28 , haddockFlags :: HaddockFlags
29 , testFlags :: TestFlags
30 , benchmarkFlags :: BenchmarkFlags
31 , projectFlags :: ProjectFlags
32 , extraFlags :: a
35 nixStyleOptions
36 :: (ShowOrParseArgs -> [OptionField a])
37 -> ShowOrParseArgs -> [OptionField (NixStyleFlags a)]
38 nixStyleOptions commandOptions showOrParseArgs =
39 liftOptions configFlags set1
40 -- Note: [Hidden Flags]
41 -- hide "constraint", "dependency", and
42 -- "exact-configuration" from the configure options.
43 (filter ((`notElem` ["constraint", "dependency"
44 , "exact-configuration"])
45 . optionName) $ configureOptions showOrParseArgs)
46 ++ liftOptions configExFlags set2 (configureExOptions showOrParseArgs
47 ConstraintSourceCommandlineFlag)
48 ++ liftOptions installFlags set3
49 -- hide "target-package-db" and "symlink-bindir" flags from the
50 -- install options.
51 -- "symlink-bindir" is obsoleted by "installdir" in ClientInstallFlags
52 (filter ((`notElem` ["target-package-db", "symlink-bindir"])
53 . optionName) $
54 installOptions showOrParseArgs)
55 ++ liftOptions haddockFlags set4
56 -- hide "verbose" and "builddir" flags from the
57 -- haddock options.
58 (filter ((`notElem` ["v", "verbose", "builddir"])
59 . optionName) $
60 haddockOptions showOrParseArgs)
61 ++ liftOptions testFlags set5 (testOptions showOrParseArgs)
62 ++ liftOptions benchmarkFlags set6 (benchmarkOptions showOrParseArgs)
63 ++ liftOptions projectFlags set7 (projectFlagsOptions showOrParseArgs)
64 ++ liftOptions extraFlags set8 (commandOptions showOrParseArgs)
65 where
66 set1 x flags = flags { configFlags = x }
67 set2 x flags = flags { configExFlags = x }
68 set3 x flags = flags { installFlags = x }
69 set4 x flags = flags { haddockFlags = x }
70 set5 x flags = flags { testFlags = x }
71 set6 x flags = flags { benchmarkFlags = x }
72 set7 x flags = flags { projectFlags = x }
73 set8 x flags = flags { extraFlags = x }
75 defaultNixStyleFlags :: a -> NixStyleFlags a
76 defaultNixStyleFlags x = NixStyleFlags
77 { configFlags = mempty
78 , configExFlags = mempty
79 , installFlags = mempty
80 , haddockFlags = mempty
81 , testFlags = mempty
82 , benchmarkFlags = mempty
83 , projectFlags = defaultProjectFlags
84 , extraFlags = x