on master help sign in
move the Terminal API into terminal/impl/

This also does some renaming in the Terminal module: Interface => Command simple => command complex => app So now you have a Terminal.app made up of a bunch of Terminal.Command specifications.

commit171e83427eb29b6f4dff6e656330ea9467cfd6d7 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 7 Oct 2019, 16:02 (7 years ago) parent3f919f2
8 files changed+80−78
elm.cabal+6−5 terminal/src/Terminal/Args.hs → terminal/impl/Terminal.hs+28−25 terminal/src/Terminal/Args/Chomp.hs → terminal/impl/Terminal/Chomp.hs+4−5 terminal/src/Terminal/Args/Error.hs → terminal/impl/Terminal/Error.hs+12−13 terminal/src/Terminal/Args/Helpers.hs → terminal/impl/Terminal/Helpers.hs+2−2 terminal/src/Terminal/Args/Internal.hs → terminal/impl/Terminal/Internal.hs+8−8 terminal/src/Main.hs+19−19 terminal/src/Make.hs+1−1
elm.cabal+6−5
@@ -45,6 +45,7 @@ Executable elm
4545 Hs-Source-Dirs:
4646 compiler/src
4747 builder/src
48+ terminal/impl
4849 terminal/src
4950
5051 other-extensions:
@@ -64,11 +65,11 @@ Executable elm
6465 Repl
6566
6667 -- terminal args
67− Terminal.Args
68− Terminal.Args.Chomp
69− Terminal.Args.Error
70− Terminal.Args.Helpers
71− Terminal.Args.Internal
68+ Terminal
69+ Terminal.Chomp
70+ Terminal.Error
71+ Terminal.Helpers
72+ Terminal.Internal
7273
7374 -- from terminal/
7475 Develop.Generate.Help
terminal/src/Terminal/Args.hs → terminal/impl/Terminal.hsrenamed+28−25
@@ -1,8 +1,7 @@
1−module Terminal.Args
2− ( simple
3− , Interface(..)
1+module Terminal
2+ ( app
3+ , Command(..)
44 , Summary(..)
5− , complex
65 , Flags, noFlags, flags, (|--)
76 , Flag, flag, onOff
87 , Parser(..)
@@ -26,17 +25,17 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
2625import qualified Text.Read as Read
2726
2827import qualified Elm.Version as V
29−import Terminal.Args.Internal
30−import qualified Terminal.Args.Chomp as Chomp
31−import qualified Terminal.Args.Error as Error
28+import Terminal.Internal
29+import qualified Terminal.Chomp as Chomp
30+import qualified Terminal.Error as Error
3231
3332
3433
35−-- GET
34+-- COMMAND
3635
3736
38−simple :: String -> P.Doc -> Args args -> Flags flags -> (args -> flags -> IO ()) -> IO ()
39−simple details example args_ flags_ callback =
37+_command :: String -> P.Doc -> Args args -> Flags flags -> (args -> flags -> IO ()) -> IO ()
38+_command details example args_ flags_ callback =
4039 do setLocaleEncoding utf8
4140 argStrings <- Env.getArgs
4241 case argStrings of
@@ -57,34 +56,38 @@ simple details example args_ flags_ callback =
5756 Error.exitWithError err
5857
5958
60−complex :: P.Doc -> P.Doc -> [Interface] -> IO ()
61−complex intro outro interfaces =
59+
60+-- APP
61+
62+
63+app :: P.Doc -> P.Doc -> [Command] -> IO ()
64+app intro outro commands =
6265 do setLocaleEncoding utf8
6366 argStrings <- Env.getArgs
6467 case argStrings of
6568 [] ->
66− Error.exitWithOverview intro outro interfaces
69+ Error.exitWithOverview intro outro commands
6770
6871 ["--help"] ->
69− Error.exitWithOverview intro outro interfaces
72+ Error.exitWithOverview intro outro commands
7073
7174 ["--version"] ->
7275 do hPutStrLn stdout (V.toChars V.compiler ++ "-rc-1")
7376 Exit.exitSuccess
7477
7578 command : chunks ->
76− do case List.find (\iface -> toName iface == command) interfaces of
79+ do case List.find (\cmd -> toName cmd == command) commands of
7780 Nothing ->
78− Error.exitWithUnknown command (map toName interfaces)
81+ Error.exitWithUnknown command (map toName commands)
7982
80− Just (Interface _ _ details example args_ flags_ callback) ->
83+ Just (Command _ _ details example args_ flags_ callback) ->
8184 if elem "--help" chunks then
8285 Error.exitWithHelp (Just command) details example args_ flags_
8386
8487 else
8588 case snd $ Chomp.chomp Nothing chunks args_ flags_ of
86− Right (argsValue, flagValue) ->
87− callback argsValue flagValue
89+ Right (argsValue, flagsValue) ->
90+ callback argsValue flagsValue
8891
8992 Left err ->
9093 Error.exitWithError err
@@ -159,21 +162,21 @@ findIndex index point chunks =
159162 findIndex (index + 1) point cs
160163
161164
162−_complexSuggest :: [Interface] -> Int -> [String] -> IO [String]
163−_complexSuggest interfaces index strings =
165+_complexSuggest :: [Command] -> Int -> [String] -> IO [String]
166+_complexSuggest commands index strings =
164167 case strings of
165168 [] ->
166− return (map toName interfaces)
169+ return (map toName commands)
167170
168171 command : chunks ->
169172 if index == 1 then
170− return (filter (List.isPrefixOf command) (map toName interfaces))
173+ return (filter (List.isPrefixOf command) (map toName commands))
171174 else
172− case List.find (\iface -> toName iface == command) interfaces of
175+ case List.find (\cmd -> toName cmd == command) commands of
173176 Nothing ->
174177 return []
175178
176− Just (Interface _ _ _ _ args_ flags_ _) ->
179+ Just (Command _ _ _ _ args_ flags_ _) ->
177180 fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
178181
179182
terminal/src/Terminal/Args/Chomp.hs → terminal/impl/Terminal/Chomp.hsrenamed+4−5
@@ -1,6 +1,5 @@
1−{-# LANGUAGE GADTs #-}
2−{-# LANGUAGE Rank2Types #-}
3−module Terminal.Args.Chomp
1+{-# LANGUAGE GADTs, Rank2Types #-}
2+module Terminal.Chomp
43 ( chomp
54 )
65 where
@@ -8,8 +7,8 @@ module Terminal.Args.Chomp
87
98import qualified Data.List as List
109
11−import Terminal.Args.Error
12−import Terminal.Args.Internal
10+import Terminal.Error
11+import Terminal.Internal
1312
1413
1514
terminal/src/Terminal/Args/Error.hs → terminal/impl/Terminal/Error.hsrenamed+12−13
@@ -1,6 +1,5 @@
1−{-# LANGUAGE GADTs #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Terminal.Args.Error
1+{-# LANGUAGE GADTs, OverloadedStrings #-}
2+module Terminal.Error
43 ( Error(..)
54 , ArgError(..)
65 , FlagError(..)
@@ -24,7 +23,7 @@ import System.IO (hPutStrLn, stderr)
2423import qualified Text.PrettyPrint.ANSI.Leijen as P
2524
2625import Reporting.Suggest as Suggest
27−import Terminal.Args.Internal
26+import Terminal.Internal
2827
2928
3029
@@ -187,22 +186,22 @@ flagsToDocs flags docs =
187186-- OVERVIEW
188187
189188
190−exitWithOverview :: P.Doc -> P.Doc -> [Interface] -> IO a
191−exitWithOverview intro outro interfaces =
189+exitWithOverview :: P.Doc -> P.Doc -> [Command] -> IO a
190+exitWithOverview intro outro commands =
192191 do exeName <- getExeName
193192 exitSuccess
194193 [ intro
195194 , "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
197196 , "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
199198 , "Adding the --help flag gives a bunch of additional details about each one."
200199 , outro
201200 ]
202201
203202
204−toSummary :: String -> Interface -> Maybe P.Doc
205−toSummary exeName (Interface name summary _ _ (Args args) _ _) =
203+toSummary :: String -> Command -> Maybe P.Doc
204+toSummary exeName (Command name summary _ _ (Args args) _ _) =
206205 case summary of
207206 Uncommon ->
208207 Nothing
@@ -215,10 +214,10 @@ toSummary exeName (Interface name summary _ _ (Args args) _ _) =
215214 ]
216215
217216
218−toCommandList :: String -> [Interface] -> P.Doc
219−toCommandList exeName interfaces =
217+toCommandList :: String -> [Command] -> P.Doc
218+toCommandList exeName commands =
220219 let
221− names = map toName interfaces
220+ names = map toName commands
222221 width = maximum (map length names)
223222
224223 toExample name =
terminal/src/Terminal/Args/Helpers.hs → terminal/impl/Terminal/Helpers.hsrenamed+2−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2−module Terminal.Args.Helpers
2+module Terminal.Helpers
33 ( version
44 , elmFile
55 , package
@@ -14,7 +14,7 @@ import qualified Data.Map as Map
1414import qualified Data.Utf8 as Utf8
1515import qualified System.FilePath as FP
1616
17−import Terminal.Args (Parser(..))
17+import Terminal (Parser(..))
1818import qualified Deps.Registry as Registry
1919import qualified Elm.Package as Pkg
2020import qualified Elm.Version as V
terminal/src/Terminal/Args/Internal.hs → terminal/impl/Terminal/Internal.hsrenamed+8−8
@@ -1,6 +1,6 @@
11{-# LANGUAGE GADTs #-}
2−module Terminal.Args.Internal
3− ( Interface(..)
2+module Terminal.Internal
3+ ( Command(..)
44 , toName
55 , Summary(..)
66 , Flags(..)
@@ -17,11 +17,11 @@ import Text.PrettyPrint.ANSI.Leijen (Doc)
1717
1818
1919
20−-- INTERFACE
20+-- COMMAND
2121
2222
23−data Interface where
24− Interface
23+data Command where
24+ Command
2525 :: String
2626 -> Summary
2727 -> String
@@ -29,11 +29,11 @@ data Interface where
2929 -> Args args
3030 -> Flags flags
3131 -> (args -> flags -> IO ())
32− -> Interface
32+ -> Command
3333
3434
35−toName :: Interface -> String
36−toName (Interface name _ _ _ _ _ _) =
35+toName :: Command -> String
36+toName (Command name _ _ _ _ _ _) =
3737 name
3838
3939
terminal/src/Main.hs+19−19
@@ -12,8 +12,8 @@ import Text.PrettyPrint.ANSI.Leijen ((<>))
1212import Text.Read (readMaybe)
1313
1414import qualified Elm.Version as V
15−import Terminal.Args
16−import Terminal.Args.Helpers
15+import Terminal
16+import Terminal.Helpers
1717
1818import qualified Bump
1919import qualified Develop
@@ -31,7 +31,7 @@ import qualified Repl
3131
3232main :: IO ()
3333main =
34− complex intro outro
34+ Terminal.app intro outro
3535 [ repl
3636 , init
3737 , reactor
@@ -72,7 +72,7 @@ outro =
7272-- INIT
7373
7474
75−init :: Interface
75+init :: Terminal.Command
7676init =
7777 let
7878 summary =
@@ -87,14 +87,14 @@ init =
8787 "It will ask permission to create an elm.json file, the one thing common\
8888 \ to all Elm projects. It also provides a link explaining what to do from there."
8989 in
90− Interface "init" (Common summary) details example noArgs noFlags Init.run
90+ Terminal.Command "init" (Common summary) details example noArgs noFlags Init.run
9191
9292
9393
9494-- REPL
9595
9696
97−repl :: Interface
97+repl :: Terminal.Command
9898repl =
9999 let
100100 summary =
@@ -115,7 +115,7 @@ repl =
115115 |-- flag "interpreter" interpreter "Path to a alternate JS interpreter, like node or nodejs."
116116 |-- 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."
117117 in
118− Interface "repl" (Common summary) details example noArgs replFlags Repl.run
118+ Terminal.Command "repl" (Common summary) details example noArgs replFlags Repl.run
119119
120120
121121interpreter :: Parser String
@@ -133,7 +133,7 @@ interpreter =
133133-- REACTOR
134134
135135
136−reactor :: Interface
136+reactor :: Terminal.Command
137137reactor =
138138 let
139139 summary =
@@ -154,7 +154,7 @@ reactor =
154154 flags Develop.Flags
155155 |-- flag "port" port_ "The port of the server (default: 8000)"
156156 in
157− Interface "reactor" (Common summary) details example noArgs reactorFlags Develop.run
157+ Terminal.Command "reactor" (Common summary) details example noArgs reactorFlags Develop.run
158158
159159
160160port_ :: Parser Int
@@ -172,7 +172,7 @@ port_ =
172172-- MAKE
173173
174174
175−make :: Interface
175+make :: Terminal.Command
176176make =
177177 let
178178 details =
@@ -196,14 +196,14 @@ make =
196196 |-- 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!"
197197 |-- 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."
198198 in
199− Interface "make" Uncommon details example (zeroOrMore elmFile) makeFlags Make.run
199+ Terminal.Command "make" Uncommon details example (zeroOrMore elmFile) makeFlags Make.run
200200
201201
202202
203203-- INSTALL
204204
205205
206−install :: Interface
206+install :: Terminal.Command
207207install =
208208 let
209209 details =
@@ -232,14 +232,14 @@ install =
232232 , require1 Install.Install package
233233 ]
234234 in
235− Interface "install" Uncommon details example installArgs noFlags Install.run
235+ Terminal.Command "install" Uncommon details example installArgs noFlags Install.run
236236
237237
238238
239239-- PUBLISH
240240
241241
242−publish :: Interface
242+publish :: Terminal.Command
243243publish =
244244 let
245245 details =
@@ -269,14 +269,14 @@ publish =
269269 "Check out <https://package.elm-lang.org/help/design-guidelines> for guidance on how to create great packages!"
270270 ]
271271 in
272− Interface "publish" Uncommon details example noArgs noFlags Publish.run
272+ Terminal.Command "publish" Uncommon details example noArgs noFlags Publish.run
273273
274274
275275
276276-- BUMP
277277
278278
279−bump :: Interface
279+bump :: Terminal.Command
280280bump =
281281 let
282282 details =
@@ -289,14 +289,14 @@ bump =
289289 \ it is a MAJOR change, and bump your version number to 2.0.0. I do this with\
290290 \ all packages, so there cannot be MAJOR changes hiding in PATCH releases in Elm!"
291291 in
292− Interface "bump" Uncommon details example noArgs noFlags Bump.run
292+ Terminal.Command "bump" Uncommon details example noArgs noFlags Bump.run
293293
294294
295295
296296-- DIFF
297297
298298
299−diff :: Interface
299+diff :: Terminal.Command
300300diff =
301301 let
302302 details =
@@ -321,7 +321,7 @@ diff =
321321 , require3 Diff.GlobalInquiry package version version
322322 ]
323323 in
324− Interface "diff" Uncommon details example diffArgs noFlags Diff.run
324+ Terminal.Command "diff" Uncommon details example diffArgs noFlags Diff.run
325325
326326
327327
terminal/src/Make.hs+1−1
@@ -29,7 +29,7 @@ import qualified Reporting
2929import qualified Reporting.Exit as Exit
3030import qualified Reporting.Task as Task
3131import qualified Stuff
32−import Terminal.Args (Parser(..))
32+import Terminal (Parser(..))
3333
3434
3535