2 {-# LANGUAGE DataKinds #-}
3 {-# LANGUAGE DeriveDataTypeable #-}
4 {-# LANGUAGE DeriveGeneric #-}
5 {-# LANGUAGE FlexibleContexts #-}
6 {-# LANGUAGE PatternSynonyms #-}
7 {-# LANGUAGE RankNTypes #-}
8 {-# LANGUAGE ViewPatterns #-}
10 -----------------------------------------------------------------------------
13 -- Module : Distribution.Simple.Setup.Repl
14 -- Copyright : Isaac Jones 2003-2004
18 -- Maintainer : cabal-devel@haskell.org
19 -- Portability : portable
21 -- Definition of the repl command-line options.
22 -- See: @Distribution.Simple.Setup@
23 module Distribution
.Simple
.Setup
.Repl
39 import Distribution
.Compat
.Prelude
hiding (get
)
42 import Distribution
.ReadE
43 import Distribution
.Simple
.Command
hiding (boolOpt
, boolOpt
')
44 import Distribution
.Simple
.Flag
45 import Distribution
.Simple
.Program
46 import Distribution
.Simple
.Setup
.Common
47 import Distribution
.Simple
.Utils
48 import Distribution
.Utils
.Path
49 import Distribution
.Verbosity
51 -- ------------------------------------------------------------
55 -- ------------------------------------------------------------
57 data ReplOptions
= ReplOptions
58 { replOptionsFlags
:: [String]
59 , replOptionsNoLoad
:: Flag
Bool
60 , replOptionsFlagOutput
:: Flag
FilePath
62 deriving (Show, Generic
, Typeable
)
64 pattern ReplCommonFlags
66 -> Flag
(SymbolicPath Pkg
(Dir Dist
))
67 -> Flag
(SymbolicPath CWD
(Dir Pkg
))
68 -> Flag
(SymbolicPath Pkg File
)
71 pattern ReplCommonFlags
80 { setupVerbosity
= replVerbosity
81 , setupDistPref
= replDistPref
82 , setupWorkingDir
= replWorkingDir
83 , setupCabalFilePath
= replCabalFilePath
84 , setupTargets
= replTargets
88 instance Binary ReplOptions
89 instance Structured ReplOptions
91 instance Monoid ReplOptions
where
92 mempty
= ReplOptions mempty
(Flag
False) NoFlag
95 instance Semigroup ReplOptions
where
98 data ReplFlags
= ReplFlags
99 { replCommonFlags
:: !CommonSetupFlags
100 , replProgramPaths
:: [(String, FilePath)]
101 , replProgramArgs
:: [(String, [String])]
102 , replReload
:: Flag
Bool
103 , replReplOptions
:: ReplOptions
105 deriving (Show, Generic
, Typeable
)
107 instance Binary ReplFlags
108 instance Structured ReplFlags
110 defaultReplFlags
:: ReplFlags
113 { replCommonFlags
= defaultCommonSetupFlags
114 , replProgramPaths
= mempty
115 , replProgramArgs
= []
116 , replReload
= Flag
False
117 , replReplOptions
= mempty
120 instance Monoid ReplFlags
where
124 instance Semigroup ReplFlags
where
127 replCommand
:: ProgramDb
-> CommandUI ReplFlags
130 { commandName
= "repl"
132 "Open an interpreter session for the given component."
133 , commandDescription
= Just
$ \pname
->
135 "If the current directory contains no package, ignores COMPONENT "
136 ++ "parameters and opens an interactive interpreter session.\n"
138 ++ "Otherwise, (re)configures with the given or default flags, and "
139 ++ "loads the interpreter with the relevant modules. For executables, "
140 ++ "tests and benchmarks, loads the main module (and its "
141 ++ "dependencies); for libraries all exposed/other modules.\n"
143 ++ "The default component is the library itself, or the executable "
144 ++ "if that is the only component.\n"
146 ++ "Support for loading specific modules is planned but not "
147 ++ "implemented yet. For certain scenarios, `"
149 ++ " exec -- ghci :l Foo` may be used instead. Note that `exec` will "
150 ++ "not (re)configure and you will have to specify the location of "
151 ++ "other modules, if required.\n"
152 , commandNotes
= Just
$ \pname
->
157 ++ " The first component in the package\n"
161 ++ " A named component (i.e. lib, exe, test suite)\n"
164 ++ " repl --repl-options=\"-lstdc++\""
165 ++ " Specifying flags for interpreter\n"
166 , -- TODO: re-enable once we have support for module/file targets
167 -- ++ " " ++ pname ++ " repl Foo.Bar "
169 -- ++ " " ++ pname ++ " repl Foo/Bar.hs"
171 -- ++ "If a target is ambiguous it can be qualified with the component "
173 -- ++ " " ++ pname ++ " repl foo:Foo.Bar\n"
174 -- ++ " " ++ pname ++ " repl testsuite1:Foo/Bar.hs\n"
175 commandUsage
= \pname
-> "Usage: " ++ pname
++ " repl [COMPONENT] [FLAGS]\n"
176 , commandDefaultFlags
= defaultReplFlags
177 , commandOptions
= \showOrParseArgs
->
178 withCommonSetupOptions
180 (\c f
-> f
{replCommonFlags
= c
})
186 (\v flags
-> flags
{replProgramPaths
= v
})
191 (\v flags
-> flags
{replProgramArgs
= v
})
196 (\v flags
-> flags
{replProgramArgs
= v
})
197 ++ case showOrParseArgs
of
202 "Used from within an interpreter to update files."
204 (\v flags
-> flags
{replReload
= v
})
208 ++ map liftReplOption
(replOptions showOrParseArgs
)
211 liftReplOption
= liftOption replReplOptions
(\v flags
-> flags
{replReplOptions
= v
})
213 replOptions
:: ShowOrParseArgs
-> [OptionField ReplOptions
]
218 "Disable loading of project modules at REPL startup."
220 (\p flags
-> flags
{replOptionsNoLoad
= p
})
225 "Use the option(s) for the repl"
227 (\p flags
-> flags
{replOptionsFlags
= p
})
228 (reqArg
"FLAG" (succeedReadE
words) id)
232 "Write repl options to this directory rather than starting repl mode"
233 replOptionsFlagOutput
234 (\p flags
-> flags
{replOptionsFlagOutput
= p
})
235 (reqArg
"DIR" (succeedReadE Flag
) flagToList
)