2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE RankNTypes #-}
7 -----------------------------------------------------------------------------
10 -- Module : Distribution.Simple.Setup.Repl
11 -- Copyright : Isaac Jones 2003-2004
15 -- Maintainer : cabal-devel@haskell.org
16 -- Portability : portable
18 -- Definition of the repl command-line options.
19 -- See: @Distribution.Simple.Setup@
20 module Distribution
.Simple
.Setup
.Repl
28 import Distribution
.Compat
.Prelude
hiding (get
)
31 import Distribution
.ReadE
32 import Distribution
.Simple
.Command
hiding (boolOpt
, boolOpt
')
33 import Distribution
.Simple
.Flag
34 import Distribution
.Simple
.Program
35 import Distribution
.Simple
.Utils
36 import Distribution
.Verbosity
38 import Distribution
.Simple
.Setup
.Common
40 -- ------------------------------------------------------------
44 -- ------------------------------------------------------------
46 data ReplOptions
= ReplOptions
47 { replOptionsFlags
:: [String]
48 , replOptionsNoLoad
:: Flag
Bool
49 , replOptionsFlagOutput
:: Flag
FilePath
51 deriving (Show, Generic
, Typeable
)
53 instance Binary ReplOptions
54 instance Structured ReplOptions
56 instance Monoid ReplOptions
where
57 mempty
= ReplOptions mempty
(Flag
False) NoFlag
60 instance Semigroup ReplOptions
where
63 data ReplFlags
= ReplFlags
64 { replProgramPaths
:: [(String, FilePath)]
65 , replProgramArgs
:: [(String, [String])]
66 , replDistPref
:: Flag
FilePath
67 , replVerbosity
:: Flag Verbosity
68 , replReload
:: Flag
Bool
69 , replReplOptions
:: ReplOptions
71 deriving (Show, Generic
, Typeable
)
73 instance Binary ReplFlags
74 instance Structured ReplFlags
76 defaultReplFlags
:: ReplFlags
79 { replProgramPaths
= mempty
80 , replProgramArgs
= []
81 , replDistPref
= NoFlag
82 , replVerbosity
= Flag normal
83 , replReload
= Flag
False
84 , replReplOptions
= mempty
87 instance Monoid ReplFlags
where
91 instance Semigroup ReplFlags
where
94 replCommand
:: ProgramDb
-> CommandUI ReplFlags
97 { commandName
= "repl"
99 "Open an interpreter session for the given component."
100 , commandDescription
= Just
$ \pname
->
102 "If the current directory contains no package, ignores COMPONENT "
103 ++ "parameters and opens an interactive interpreter session; if a "
104 ++ "sandbox is present, its package database will be used.\n"
106 ++ "Otherwise, (re)configures with the given or default flags, and "
107 ++ "loads the interpreter with the relevant modules. For executables, "
108 ++ "tests and benchmarks, loads the main module (and its "
109 ++ "dependencies); for libraries all exposed/other modules.\n"
111 ++ "The default component is the library itself, or the executable "
112 ++ "if that is the only component.\n"
114 ++ "Support for loading specific modules is planned but not "
115 ++ "implemented yet. For certain scenarios, `"
117 ++ " exec -- ghci :l Foo` may be used instead. Note that `exec` will "
118 ++ "not (re)configure and you will have to specify the location of "
119 ++ "other modules, if required.\n"
120 , commandNotes
= Just
$ \pname
->
125 ++ " The first component in the package\n"
129 ++ " A named component (i.e. lib, exe, test suite)\n"
132 ++ " repl --repl-options=\"-lstdc++\""
133 ++ " Specifying flags for interpreter\n"
134 , -- TODO: re-enable once we have support for module/file targets
135 -- ++ " " ++ pname ++ " repl Foo.Bar "
137 -- ++ " " ++ pname ++ " repl Foo/Bar.hs"
139 -- ++ "If a target is ambiguous it can be qualified with the component "
141 -- ++ " " ++ pname ++ " repl foo:Foo.Bar\n"
142 -- ++ " " ++ pname ++ " repl testsuite1:Foo/Bar.hs\n"
143 commandUsage
= \pname
-> "Usage: " ++ pname
++ " repl [COMPONENT] [FLAGS]\n"
144 , commandDefaultFlags
= defaultReplFlags
145 , commandOptions
= \showOrParseArgs
->
146 optionVerbosity replVerbosity
(\v flags
-> flags
{replVerbosity
= v
})
149 (\d flags
-> flags
{replDistPref
= d
})
155 (\v flags
-> flags
{replProgramPaths
= v
})
160 (\v flags
-> flags
{replProgramArgs
= v
})
165 (\v flags
-> flags
{replProgramArgs
= v
})
166 ++ case showOrParseArgs
of
171 "Used from within an interpreter to update files."
173 (\v flags
-> flags
{replReload
= v
})
177 ++ map liftReplOption
(replOptions showOrParseArgs
)
180 liftReplOption
= liftOption replReplOptions
(\v flags
-> flags
{replReplOptions
= v
})
182 replOptions
:: ShowOrParseArgs
-> [OptionField ReplOptions
]
187 "Disable loading of project modules at REPL startup."
189 (\p flags
-> flags
{replOptionsNoLoad
= p
})
194 "Use the option(s) for the repl"
196 (\p flags
-> flags
{replOptionsFlags
= p
})
197 (reqArg
"FLAG" (succeedReadE
words) id)
201 "Write repl options to this directory rather than starting repl mode"
202 replOptionsFlagOutput
203 (\p flags
-> flags
{replOptionsFlagOutput
= p
})
204 (reqArg
"DIR" (succeedReadE Flag
) flagToList
)