1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE OverloadedStrings #-}
4 module Distribution
.Client
.ProjectFlags
8 , removeIgnoreProjectOption
11 import Distribution
.Client
.Compat
.Prelude
14 import Distribution
.ReadE
(succeedReadE
)
15 import Distribution
.Simple
.Command
17 , OptionField
(optionName
)
18 , ShowOrParseArgs
(..)
23 import Distribution
.Simple
.Setup
(Flag
(..), flagToList
, flagToMaybe
, toFlag
, trueArg
)
25 data ProjectFlags
= ProjectFlags
26 { flagProjectDir
:: Flag
FilePath
27 -- ^ The project directory.
28 , flagProjectFile
:: Flag
FilePath
29 -- ^ The cabal project file path; defaults to @cabal.project@.
30 -- This path, when relative, is relative to the project directory.
31 -- The filename portion of the path denotes the cabal project file name, but it also
32 -- is the base of auxiliary project files, such as
33 -- @cabal.project.local@ and @cabal.project.freeze@ which are also
34 -- read and written out in some cases.
35 -- If a project directory was not specified, and the path is not found
36 -- in the current working directory, we will successively probe
37 -- relative to parent directories until this name is found.
38 , flagIgnoreProject
:: Flag
Bool
39 -- ^ Whether to ignore the local project (i.e. don't search for cabal.project)
40 -- The exact interpretation might be slightly different per command.
42 deriving (Show, Generic
)
44 defaultProjectFlags
:: ProjectFlags
47 { flagProjectDir
= mempty
48 , flagProjectFile
= mempty
49 , flagIgnoreProject
= toFlag
False
50 -- Should we use 'Last' here?
53 projectFlagsOptions
:: ShowOrParseArgs
-> [OptionField ProjectFlags
]
54 projectFlagsOptions showOrParseArgs
=
58 "Set the path of the project directory"
60 (\path flags
-> flags
{flagProjectDir
= path
})
61 (reqArg
"DIR" (succeedReadE Flag
) flagToList
)
65 "Set the path of the cabal.project file (relative to the project directory when relative)"
67 (\pf flags
-> flags
{flagProjectFile
= pf
})
68 (reqArg
"FILE" (succeedReadE Flag
) flagToList
)
72 "Ignore local project configuration (unless --project-dir or --project-file is also set)"
76 { flagIgnoreProject
= case v
of
77 Flag
True -> toFlag
(flagProjectDir flags
== NoFlag
&& flagProjectFile flags
== NoFlag
)
81 (yesNoOpt showOrParseArgs
)
84 -- | As almost all commands use 'ProjectFlags' but not all can honour
85 -- "ignore-project" flag, provide this utility to remove the flag
86 -- parsing from the help message.
87 removeIgnoreProjectOption
:: [OptionField a
] -> [OptionField a
]
88 removeIgnoreProjectOption
= filter (\o
-> optionName o
/= "ignore-project")
90 instance Monoid ProjectFlags
where
94 instance Semigroup ProjectFlags
where
97 yesNoOpt
:: ShowOrParseArgs
-> MkOptDescr
(b
-> Flag
Bool) (Flag
Bool -> b
-> b
) b
98 yesNoOpt ShowArgs sf lf
= trueArg sf lf
99 yesNoOpt _ sf lf
= boolOpt
' flagToMaybe Flag
(sf
, lf
) ([], map ("no-" ++) lf
) sf lf