on master help sign in
move the Terminal API into terminal/impl/
171e834Evan Czaplicki
elm.cabal+6−5
@@ -45,6 +45,7 @@ Executable elm
45 Hs-Source-Dirs:
45 Hs-Source-Dirs:
46 compiler/src
46 compiler/src
47 builder/src
47 builder/src
48+ terminal/impl
48 terminal/src
49 terminal/src
49
50
50 other-extensions:
51 other-extensions:
@@ -64,11 +65,11 @@ Executable elm
64 Repl
65 Repl
65
66
66 -- terminal args
67 -- terminal args
67− Terminal.Args
68+ Terminal
68− Terminal.Args.Chomp
69+ Terminal.Chomp
69− Terminal.Args.Error
70+ Terminal.Error
70− Terminal.Args.Helpers
71+ Terminal.Helpers
71− Terminal.Args.Internal
72+ Terminal.Internal
72
73
73 -- from terminal/
74 -- from terminal/
74 Develop.Generate.Help
75 Develop.Generate.Help
terminal/src/Terminal/Args.hs → terminal/impl/Terminal.hsrenamed+28−25
@@ -1,8 +1,7 @@
1−module Terminal.Args
1+module Terminal
2− ( simple
2+ ( app
3− , Interface(..)
3+ , Command(..)
4 , Summary(..)
4 , Summary(..)
5− , complex
6 , Flags, noFlags, flags, (|--)
5 , Flags, noFlags, flags, (|--)
7 , Flag, flag, onOff
6 , Flag, flag, onOff
8 , Parser(..)
7 , Parser(..)
@@ -26,17 +25,17 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
26import qualified Text.Read as Read
25import qualified Text.Read as Read
27
26
28import qualified Elm.Version as V
27import qualified Elm.Version as V
29−import Terminal.Args.Internal
28+import Terminal.Internal
30−import qualified Terminal.Args.Chomp as Chomp
29+import qualified Terminal.Chomp as Chomp
31−import qualified Terminal.Args.Error as Error
30+import qualified Terminal.Error as Error
32
31
33
32
34
33
35−-- GET
34+-- COMMAND
36
35
37
36
38−simple :: String -> P.Doc -> Args args -> Flags flags -> (args -> flags -> IO ()) -> IO ()
37+_command :: String -> P.Doc -> Args args -> Flags flags -> (args -> flags -> IO ()) -> IO ()
39−simple details example args_ flags_ callback =
38+_command details example args_ flags_ callback =
40 do setLocaleEncoding utf8
39 do setLocaleEncoding utf8
41 argStrings <- Env.getArgs
40 argStrings <- Env.getArgs
42 case argStrings of
41 case argStrings of
@@ -57,34 +56,38 @@ simple details example args_ flags_ callback =
57 Error.exitWithError err
56 Error.exitWithError err
58
57
59
58
59+
60+-- APP
61+
62+
60−complex :: P.Doc -> P.Doc -> [Interface] -> IO ()
63+app :: P.Doc -> P.Doc -> [Command] -> IO ()
61−complex intro outro interfaces =
64+app intro outro commands =
62 do setLocaleEncoding utf8
65 do setLocaleEncoding utf8
63 argStrings <- Env.getArgs
66 argStrings <- Env.getArgs
64 case argStrings of
67 case argStrings of
65 [] ->
68 [] ->
66− Error.exitWithOverview intro outro interfaces
69+ Error.exitWithOverview intro outro commands
67
70
68 ["--help"] ->
71 ["--help"] ->
69− Error.exitWithOverview intro outro interfaces
72+ Error.exitWithOverview intro outro commands
70
73
71 ["--version"] ->
74 ["--version"] ->
72 do hPutStrLn stdout (V.toChars V.compiler ++ "-rc-1")
75 do hPutStrLn stdout (V.toChars V.compiler ++ "-rc-1")
73 Exit.exitSuccess
76 Exit.exitSuccess
74
77
75 command : chunks ->
78 command : chunks ->
76− do case List.find (\iface -> toName iface == command) interfaces of
79+ do case List.find (\cmd -> toName cmd == command) commands of
77 Nothing ->
80 Nothing ->
78− Error.exitWithUnknown command (map toName interfaces)
81+ Error.exitWithUnknown command (map toName commands)
79
82
80− Just (Interface _ _ details example args_ flags_ callback) ->
83+ Just (Command _ _ details example args_ flags_ callback) ->
81 if elem "--help" chunks then
84 if elem "--help" chunks then
82 Error.exitWithHelp (Just command) details example args_ flags_
85 Error.exitWithHelp (Just command) details example args_ flags_
83
86
84 else
87 else
85 case snd $ Chomp.chomp Nothing chunks args_ flags_ of
88 case snd $ Chomp.chomp Nothing chunks args_ flags_ of
86− Right (argsValue, flagValue) ->
89+ Right (argsValue, flagsValue) ->
87− callback argsValue flagValue
90+ callback argsValue flagsValue
88
91
89 Left err ->
92 Left err ->
90 Error.exitWithError err
93 Error.exitWithError err
@@ -159,21 +162,21 @@ findIndex index point chunks =
159 findIndex (index + 1) point cs
162 findIndex (index + 1) point cs
160
163
161
164
162−_complexSuggest :: [Interface] -> Int -> [String] -> IO [String]
165+_complexSuggest :: [Command] -> Int -> [String] -> IO [String]
163−_complexSuggest interfaces index strings =
166+_complexSuggest commands index strings =
164 case strings of
167 case strings of
165 [] ->
168 [] ->
166− return (map toName interfaces)
169+ return (map toName commands)
167
170
168 command : chunks ->
171 command : chunks ->
169 if index == 1 then
172 if index == 1 then
170− return (filter (List.isPrefixOf command) (map toName interfaces))
173+ return (filter (List.isPrefixOf command) (map toName commands))
171 else
174 else
172− case List.find (\iface -> toName iface == command) interfaces of
175+ case List.find (\cmd -> toName cmd == command) commands of
173 Nothing ->
176 Nothing ->
174 return []
177 return []
175
178
176− Just (Interface _ _ _ _ args_ flags_ _) ->
179+ Just (Command _ _ _ _ args_ flags_ _) ->
177 fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
180 fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
178
181
179
182
terminal/src/Terminal/Args/Chomp.hs → terminal/impl/Terminal/Chomp.hsrenamed+4−5
@@ -1,6 +1,5 @@
1−{-# LANGUAGE GADTs #-}
1+{-# LANGUAGE GADTs, Rank2Types #-}
2−{-# LANGUAGE Rank2Types #-}
3−module Terminal.Args.Chomp
2+module Terminal.Chomp
4 ( chomp
3 ( chomp
5 )
4 )
6 where
5 where
@@ -8,8 +7,8 @@ module Terminal.Args.Chomp
8
7
9import qualified Data.List as List
8import qualified Data.List as List
10
9
11−import Terminal.Args.Error
10+import Terminal.Error
12−import Terminal.Args.Internal
11+import Terminal.Internal
13
12
14
13
15
14
terminal/src/Terminal/Args/Error.hs → terminal/impl/Terminal/Error.hsrenamed+12−13
@@ -1,6 +1,5 @@
1−{-# LANGUAGE GADTs #-}
2−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE GADTs, OverloadedStrings #-}
3−module Terminal.Args.Error
2+module Terminal.Error
4 ( Error(..)
3 ( Error(..)
5 , ArgError(..)
4 , ArgError(..)
6 , FlagError(..)
5 , FlagError(..)
@@ -24,7 +23,7 @@ import System.IO (hPutStrLn, stderr)
24import qualified Text.PrettyPrint.ANSI.Leijen as P
23import qualified Text.PrettyPrint.ANSI.Leijen as P
25
24
26import Reporting.Suggest as Suggest
25import Reporting.Suggest as Suggest
27−import Terminal.Args.Internal
26+import Terminal.Internal
28
27
29
28
30
29
@@ -187,22 +186,22 @@ flagsToDocs flags docs =
187-- OVERVIEW
186-- OVERVIEW
188
187
189
188
190−exitWithOverview :: P.Doc -> P.Doc -> [Interface] -> IO a
189+exitWithOverview :: P.Doc -> P.Doc -> [Command] -> IO a
191−exitWithOverview intro outro interfaces =
190+exitWithOverview intro outro commands =
192 do exeName <- getExeName
191 do exeName <- getExeName
193 exitSuccess
192 exitSuccess
194 [ intro
193 [ intro
195 , "The most common commands are:"
194 , "The most common commands are:"
196− , P.indent 4 $ stack $ Maybe.mapMaybe (toSummary exeName) interfaces
195+ , P.indent 4 $ stack $ Maybe.mapMaybe (toSummary exeName) commands
197 , "There are a bunch of other commands as well though. Here is a full list:"
196 , "There are a bunch of other commands as well though. Here is a full list:"
198− , P.indent 4 $ P.dullcyan $ toCommandList exeName interfaces
197+ , P.indent 4 $ P.dullcyan $ toCommandList exeName commands
199 , "Adding the --help flag gives a bunch of additional details about each one."
198 , "Adding the --help flag gives a bunch of additional details about each one."
200 , outro
199 , outro
201 ]
200 ]
202
201
203
202
204−toSummary :: String -> Interface -> Maybe P.Doc
203+toSummary :: String -> Command -> Maybe P.Doc
205−toSummary exeName (Interface name summary _ _ (Args args) _ _) =
204+toSummary exeName (Command name summary _ _ (Args args) _ _) =
206 case summary of
205 case summary of
207 Uncommon ->
206 Uncommon ->
208 Nothing
207 Nothing
@@ -215,10 +214,10 @@ toSummary exeName (Interface name summary _ _ (Args args) _ _) =
215 ]
214 ]
216
215
217
216
218−toCommandList :: String -> [Interface] -> P.Doc
217+toCommandList :: String -> [Command] -> P.Doc
219−toCommandList exeName interfaces =
218+toCommandList exeName commands =
220 let
219 let
221− names = map toName interfaces
220+ names = map toName commands
222 width = maximum (map length names)
221 width = maximum (map length names)
223
222
224 toExample name =
223 toExample name =
terminal/src/Terminal/Args/Helpers.hs → terminal/impl/Terminal/Helpers.hsrenamed+2−2
@@ -1,5 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2−module Terminal.Args.Helpers
2+module Terminal.Helpers
3 ( version
3 ( version
4 , elmFile
4 , elmFile
5 , package
5 , package
@@ -14,7 +14,7 @@ import qualified Data.Map as Map
14import qualified Data.Utf8 as Utf8
14import qualified Data.Utf8 as Utf8
15import qualified System.FilePath as FP
15import qualified System.FilePath as FP
16
16
17−import Terminal.Args (Parser(..))
17+import Terminal (Parser(..))
18import qualified Deps.Registry as Registry
18import qualified Deps.Registry as Registry
19import qualified Elm.Package as Pkg
19import qualified Elm.Package as Pkg
20import qualified Elm.Version as V
20import qualified Elm.Version as V
terminal/src/Terminal/Args/Internal.hs → terminal/impl/Terminal/Internal.hsrenamed+8−8
@@ -1,6 +1,6 @@
1{-# LANGUAGE GADTs #-}
1{-# LANGUAGE GADTs #-}
2−module Terminal.Args.Internal
2+module Terminal.Internal
3− ( Interface(..)
3+ ( Command(..)
4 , toName
4 , toName
5 , Summary(..)
5 , Summary(..)
6 , Flags(..)
6 , Flags(..)
@@ -17,11 +17,11 @@ import Text.PrettyPrint.ANSI.Leijen (Doc)
17
17
18
18
19
19
20−-- INTERFACE
20+-- COMMAND
21
21
22
22
23−data Interface where
23+data Command where
24− Interface
24+ Command
25 :: String
25 :: String
26 -> Summary
26 -> Summary
27 -> String
27 -> String
@@ -29,11 +29,11 @@ data Interface where
29 -> Args args
29 -> Args args
30 -> Flags flags
30 -> Flags flags
31 -> (args -> flags -> IO ())
31 -> (args -> flags -> IO ())
32− -> Interface
32+ -> Command
33
33
34
34
35−toName :: Interface -> String
35+toName :: Command -> String
36−toName (Interface name _ _ _ _ _ _) =
36+toName (Command name _ _ _ _ _ _) =
37 name
37 name
38
38
39
39
terminal/src/Main.hs+19−19
@@ -12,8 +12,8 @@ import Text.PrettyPrint.ANSI.Leijen ((<>))
12import Text.Read (readMaybe)
12import Text.Read (readMaybe)
13
13
14import qualified Elm.Version as V
14import qualified Elm.Version as V
15−import Terminal.Args
15+import Terminal
16−import Terminal.Args.Helpers
16+import Terminal.Helpers
17
17
18import qualified Bump
18import qualified Bump
19import qualified Develop
19import qualified Develop
@@ -31,7 +31,7 @@ import qualified Repl
31
31
32main :: IO ()
32main :: IO ()
33main =
33main =
34− complex intro outro
34+ Terminal.app intro outro
35 [ repl
35 [ repl
36 , init
36 , init
37 , reactor
37 , reactor
@@ -72,7 +72,7 @@ outro =
72-- INIT
72-- INIT
73
73
74
74
75−init :: Interface
75+init :: Terminal.Command
76init =
76init =
77 let
77 let
78 summary =
78 summary =
@@ -87,14 +87,14 @@ init =
87 "It will ask permission to create an elm.json file, the one thing common\
87 "It will ask permission to create an elm.json file, the one thing common\
88 \ to all Elm projects. It also provides a link explaining what to do from there."
88 \ to all Elm projects. It also provides a link explaining what to do from there."
89 in
89 in
90− Interface "init" (Common summary) details example noArgs noFlags Init.run
90+ Terminal.Command "init" (Common summary) details example noArgs noFlags Init.run
91
91
92
92
93
93
94-- REPL
94-- REPL
95
95
96
96
97−repl :: Interface
97+repl :: Terminal.Command
98repl =
98repl =
99 let
99 let
100 summary =
100 summary =
@@ -115,7 +115,7 @@ repl =
115 |-- flag "interpreter" interpreter "Path to a alternate JS interpreter, like node or nodejs."
115 |-- flag "interpreter" interpreter "Path to a alternate JS interpreter, like node or nodejs."
116 |-- onOff "no-colors" "Turn off the colors in the REPL. This can help if you are having trouble reading the values. Some terminals use a custom color scheme that diverges significantly from the standard ANSI colors, so another path may be to pick a more standard color scheme."
116 |-- onOff "no-colors" "Turn off the colors in the REPL. This can help if you are having trouble reading the values. Some terminals use a custom color scheme that diverges significantly from the standard ANSI colors, so another path may be to pick a more standard color scheme."
117 in
117 in
118− Interface "repl" (Common summary) details example noArgs replFlags Repl.run
118+ Terminal.Command "repl" (Common summary) details example noArgs replFlags Repl.run
119
119
120
120
121interpreter :: Parser String
121interpreter :: Parser String
@@ -133,7 +133,7 @@ interpreter =
133-- REACTOR
133-- REACTOR
134
134
135
135
136−reactor :: Interface
136+reactor :: Terminal.Command
137reactor =
137reactor =
138 let
138 let
139 summary =
139 summary =
@@ -154,7 +154,7 @@ reactor =
154 flags Develop.Flags
154 flags Develop.Flags
155 |-- flag "port" port_ "The port of the server (default: 8000)"
155 |-- flag "port" port_ "The port of the server (default: 8000)"
156 in
156 in
157− Interface "reactor" (Common summary) details example noArgs reactorFlags Develop.run
157+ Terminal.Command "reactor" (Common summary) details example noArgs reactorFlags Develop.run
158
158
159
159
160port_ :: Parser Int
160port_ :: Parser Int
@@ -172,7 +172,7 @@ port_ =
172-- MAKE
172-- MAKE
173
173
174
174
175−make :: Interface
175+make :: Terminal.Command
176make =
176make =
177 let
177 let
178 details =
178 details =
@@ -196,14 +196,14 @@ make =
196 |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!"
196 |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!"
197 |-- flag "docs" Make.docsFile "Generate a JSON file of documentation for a package. Eventually it will be possible to preview docs with `reactor` because it is quite hard to deal with these JSON files directly."
197 |-- flag "docs" Make.docsFile "Generate a JSON file of documentation for a package. Eventually it will be possible to preview docs with `reactor` because it is quite hard to deal with these JSON files directly."
198 in
198 in
199− Interface "make" Uncommon details example (zeroOrMore elmFile) makeFlags Make.run
199+ Terminal.Command "make" Uncommon details example (zeroOrMore elmFile) makeFlags Make.run
200
200
201
201
202
202
203-- INSTALL
203-- INSTALL
204
204
205
205
206−install :: Interface
206+install :: Terminal.Command
207install =
207install =
208 let
208 let
209 details =
209 details =
@@ -232,14 +232,14 @@ install =
232 , require1 Install.Install package
232 , require1 Install.Install package
233 ]
233 ]
234 in
234 in
235− Interface "install" Uncommon details example installArgs noFlags Install.run
235+ Terminal.Command "install" Uncommon details example installArgs noFlags Install.run
236
236
237
237
238
238
239-- PUBLISH
239-- PUBLISH
240
240
241
241
242−publish :: Interface
242+publish :: Terminal.Command
243publish =
243publish =
244 let
244 let
245 details =
245 details =
@@ -269,14 +269,14 @@ publish =
269 "Check out <https://package.elm-lang.org/help/design-guidelines> for guidance on how to create great packages!"
269 "Check out <https://package.elm-lang.org/help/design-guidelines> for guidance on how to create great packages!"
270 ]
270 ]
271 in
271 in
272− Interface "publish" Uncommon details example noArgs noFlags Publish.run
272+ Terminal.Command "publish" Uncommon details example noArgs noFlags Publish.run
273
273
274
274
275
275
276-- BUMP
276-- BUMP
277
277
278
278
279−bump :: Interface
279+bump :: Terminal.Command
280bump =
280bump =
281 let
281 let
282 details =
282 details =
@@ -289,14 +289,14 @@ bump =
289 \ it is a MAJOR change, and bump your version number to 2.0.0. I do this with\
289 \ it is a MAJOR change, and bump your version number to 2.0.0. I do this with\
290 \ all packages, so there cannot be MAJOR changes hiding in PATCH releases in Elm!"
290 \ all packages, so there cannot be MAJOR changes hiding in PATCH releases in Elm!"
291 in
291 in
292− Interface "bump" Uncommon details example noArgs noFlags Bump.run
292+ Terminal.Command "bump" Uncommon details example noArgs noFlags Bump.run
293
293
294
294
295
295
296-- DIFF
296-- DIFF
297
297
298
298
299−diff :: Interface
299+diff :: Terminal.Command
300diff =
300diff =
301 let
301 let
302 details =
302 details =
@@ -321,7 +321,7 @@ diff =
321 , require3 Diff.GlobalInquiry package version version
321 , require3 Diff.GlobalInquiry package version version
322 ]
322 ]
323 in
323 in
324− Interface "diff" Uncommon details example diffArgs noFlags Diff.run
324+ Terminal.Command "diff" Uncommon details example diffArgs noFlags Diff.run
325
325
326
326
327
327
terminal/src/Make.hs+1−1
@@ -29,7 +29,7 @@ import qualified Reporting
29import qualified Reporting.Exit as Exit
29import qualified Reporting.Exit as Exit
30import qualified Reporting.Task as Task
30import qualified Reporting.Task as Task
31import qualified Stuff
31import qualified Stuff
32−import Terminal.Args (Parser(..))
32+import Terminal (Parser(..))
33
33
34
34
35
35