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 defaultReplFlags
:: ReplFlags
76 { replProgramPaths
= mempty
77 , replProgramArgs
= []
78 , replDistPref
= NoFlag
79 , replVerbosity
= Flag normal
80 , replReload
= Flag
False
81 , replReplOptions
= mempty
84 instance Monoid ReplFlags
where
88 instance Semigroup ReplFlags
where
91 replCommand
:: ProgramDb
-> CommandUI ReplFlags
94 { commandName
= "repl"
96 "Open an interpreter session for the given component."
97 , commandDescription
= Just
$ \pname
->
99 "If the current directory contains no package, ignores COMPONENT "
100 ++ "parameters and opens an interactive interpreter session; if a "
101 ++ "sandbox is present, its package database will be used.\n"
103 ++ "Otherwise, (re)configures with the given or default flags, and "
104 ++ "loads the interpreter with the relevant modules. For executables, "
105 ++ "tests and benchmarks, loads the main module (and its "
106 ++ "dependencies); for libraries all exposed/other modules.\n"
108 ++ "The default component is the library itself, or the executable "
109 ++ "if that is the only component.\n"
111 ++ "Support for loading specific modules is planned but not "
112 ++ "implemented yet. For certain scenarios, `"
114 ++ " exec -- ghci :l Foo` may be used instead. Note that `exec` will "
115 ++ "not (re)configure and you will have to specify the location of "
116 ++ "other modules, if required.\n"
117 , commandNotes
= Just
$ \pname
->
122 ++ " The first component in the package\n"
126 ++ " A named component (i.e. lib, exe, test suite)\n"
129 ++ " repl --repl-options=\"-lstdc++\""
130 ++ " Specifying flags for interpreter\n"
131 , -- TODO: re-enable once we have support for module/file targets
132 -- ++ " " ++ pname ++ " repl Foo.Bar "
134 -- ++ " " ++ pname ++ " repl Foo/Bar.hs"
136 -- ++ "If a target is ambiguous it can be qualified with the component "
138 -- ++ " " ++ pname ++ " repl foo:Foo.Bar\n"
139 -- ++ " " ++ pname ++ " repl testsuite1:Foo/Bar.hs\n"
140 commandUsage
= \pname
-> "Usage: " ++ pname
++ " repl [COMPONENT] [FLAGS]\n"
141 , commandDefaultFlags
= defaultReplFlags
142 , commandOptions
= \showOrParseArgs
->
143 optionVerbosity replVerbosity
(\v flags
-> flags
{replVerbosity
= v
})
146 (\d flags
-> flags
{replDistPref
= d
})
152 (\v flags
-> flags
{replProgramPaths
= v
})
157 (\v flags
-> flags
{replProgramArgs
= v
})
162 (\v flags
-> flags
{replProgramArgs
= v
})
163 ++ case showOrParseArgs
of
168 "Used from within an interpreter to update files."
170 (\v flags
-> flags
{replReload
= v
})
174 ++ map liftReplOption
(replOptions showOrParseArgs
)
177 liftReplOption
= liftOption replReplOptions
(\v flags
-> flags
{replReplOptions
= v
})
179 replOptions
:: ShowOrParseArgs
-> [OptionField ReplOptions
]
184 "Disable loading of project modules at REPL startup."
186 (\p flags
-> flags
{replOptionsNoLoad
= p
})
191 "Use the option(s) for the repl"
193 (\p flags
-> flags
{replOptionsFlags
= p
})
194 (reqArg
"FLAG" (succeedReadE
words) id)
198 "Write repl options to this directory rather than starting repl mode"
199 replOptionsFlagOutput
200 (\p flags
-> flags
{replOptionsFlagOutput
= p
})
201 (reqArg
"DIR" (succeedReadE Flag
) flagToList
)