never executed always true always false
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 module Distribution.Client.ProjectFlags (
4 ProjectFlags(..),
5 defaultProjectFlags,
6 projectFlagsOptions,
7 ) where
8
9 import Distribution.Client.Compat.Prelude
10 import Prelude ()
11
12 import Distribution.ReadE (succeedReadE)
13 import Distribution.Simple.Command (MkOptDescr, OptionField, ShowOrParseArgs (..), boolOpt', option, reqArg)
14 import Distribution.Simple.Setup (Flag (..), flagToList, flagToMaybe, toFlag, trueArg)
15
16 data ProjectFlags = ProjectFlags
17 { flagProjectFileName :: Flag FilePath
18 -- ^ The cabal project file name; defaults to @cabal.project@.
19 -- The name itself denotes the cabal project file name, but it also
20 -- is the base of auxiliary project files, such as
21 -- @cabal.project.local@ and @cabal.project.freeze@ which are also
22 -- read and written out in some cases. If the path is not found
23 -- in the current working directory, we will successively probe
24 -- relative to parent directories until this name is found.
25
26 , flagIgnoreProject :: Flag Bool
27 -- ^ Whether to ignore the local project (i.e. don't search for cabal.project)
28 -- The exact interpretation might be slightly different per command.
29 }
30 deriving (Show, Generic)
31
32 defaultProjectFlags :: ProjectFlags
33 defaultProjectFlags = ProjectFlags
34 { flagProjectFileName = mempty
35 , flagIgnoreProject = toFlag False
36 -- Should we use 'Last' here?
37 }
38
39 projectFlagsOptions :: ShowOrParseArgs -> [OptionField ProjectFlags]
40 projectFlagsOptions showOrParseArgs =
41 [ option [] ["project-file"]
42 "Set the name of the cabal.project file to search for in parent directories"
43 flagProjectFileName (\pf flags -> flags { flagProjectFileName = pf })
44 (reqArg "FILE" (succeedReadE Flag) flagToList)
45 , option ['z'] ["ignore-project"]
46 "Ignore local project configuration"
47 flagIgnoreProject (\v flags -> flags { flagIgnoreProject = v })
48 (yesNoOpt showOrParseArgs)
49 ]
50
51 instance Monoid ProjectFlags where
52 mempty = gmempty
53 mappend = (<>)
54
55 instance Semigroup ProjectFlags where
56 (<>) = gmappend
57
58 yesNoOpt :: ShowOrParseArgs -> MkOptDescr (b -> Flag Bool) (Flag Bool -> b -> b) b
59 yesNoOpt ShowArgs sf lf = trueArg sf lf
60 yesNoOpt _ sf lf = boolOpt' flagToMaybe Flag (sf, lf) ([], map ("no-" ++) lf) sf lf