1 module Distribution
.Client
.ReplFlags
(EnvFlags
(..), ReplFlags
(..), topReplOptions
, multiReplOption
, defaultReplFlags
) where
3 import Distribution
.Client
.Compat
.Prelude
6 import Distribution
.Client
.Setup
9 import Distribution
.Parsec
12 import Distribution
.ReadE
16 import Distribution
.Simple
.Command
23 import Distribution
.Simple
.Setup
32 import Distribution
.Types
.Dependency
36 data EnvFlags
= EnvFlags
37 { envPackages
:: [Dependency
]
38 , envIncludeTransitive
:: Flag
Bool
41 instance Semigroup EnvFlags
where
42 (EnvFlags a1 a2
) <> (EnvFlags b1 b2
) = EnvFlags
(a1
<> b1
) (a2
<> b2
)
44 instance Monoid EnvFlags
where
45 mempty
= defaultEnvFlags
47 defaultEnvFlags
:: EnvFlags
51 , envIncludeTransitive
= toFlag
True
54 data ReplFlags
= ReplFlags
55 { configureReplOptions
:: ReplOptions
56 , replEnvFlags
:: EnvFlags
57 , replUseMulti
:: Flag
Bool
58 , replKeepTempFiles
:: Flag
Bool
61 instance Semigroup ReplFlags
where
62 (ReplFlags a1 a2 a3 a4
) <> (ReplFlags b1 b2 b3 b4
) = ReplFlags
(a1
<> b1
) (a2
<> b2
) (a3
<> b3
) (a4
<> b4
)
64 instance Monoid ReplFlags
where
65 mempty
= defaultReplFlags
67 defaultReplFlags
:: ReplFlags
70 { configureReplOptions
= mempty
71 , replEnvFlags
= defaultEnvFlags
72 , replUseMulti
= NoFlag
73 , replKeepTempFiles
= NoFlag
76 topReplOptions
:: ShowOrParseArgs
-> [OptionField ReplFlags
]
77 topReplOptions showOrParseArgs
=
78 liftOptions configureReplOptions set1
(replOptions showOrParseArgs
)
79 ++ liftOptions replEnvFlags set2
(envOptions showOrParseArgs
)
80 ++ [ liftOption replUseMulti set3 multiReplOption
81 , -- keeping temporary files is important functionality for HLS,
82 -- which runs @cabal repl@ with fake GHC to get cli arguments.
83 -- It will need the temporary files (incl. multi unit repl response files)
84 -- to stay, even after the @cabal repl@ command exits.
89 "Keep temporary files"
91 (\b flags
-> flags
{replKeepTempFiles
= b
})
95 set1 a x
= x
{configureReplOptions
= a
}
96 set2 a x
= x
{replEnvFlags
= a
}
97 set3 a x
= x
{replUseMulti
= a
}
99 multiReplOption
:: OptionField
(Flag
Bool)
104 "multi-component repl sessions"
109 envOptions
:: ShowOrParseArgs
-> [OptionField EnvFlags
]
114 "Include additional packages in the environment presented to GHCi."
116 (\p flags
-> flags
{envPackages
= p
++ envPackages flags
})
117 (reqArg
"DEPENDENCIES" dependenciesReadE
(fmap prettyShow
:: [Dependency
] -> [String]))
120 ["no-transitive-deps"]
121 "Don't automatically include transitive dependencies of requested packages."
123 (\p flags
-> flags
{envIncludeTransitive
= p
})
127 dependenciesReadE
:: ReadE
[Dependency
]
130 ("couldn't parse dependencies: " ++)
131 (parsecCommaList parsec
)