on master help sign in
Update command implementations to always take args and flags

This means it is no longer necessary to make an intermediate data structure and pattern match on it. It also means that all the necessary data structures now live with the runner, and it can all be put together in the Main file now.

commite76d040d0568c2015a5b103a41cbb24e40559b52 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 26 Mar 2018, 18:17 (9 years ago) parent2cd952b
7 files changed+52−37
ui/terminal/src/Bump.hs+2−3 ui/terminal/src/Develop.hs+13−5 ui/terminal/src/Diff.hs+2−2 ui/terminal/src/Install.hs+2−3 ui/terminal/src/Make.hs+18−9 ui/terminal/src/Publish.hs+2−3 ui/terminal/src/Repl.hs+13−12
ui/terminal/src/Bump.hs+2−3
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21module Bump (run) where
32
43
@@ -14,8 +13,8 @@ import qualified Reporting.Progress.Terminal as Terminal
1413-- RUN
1514
1615
17−run :: IO ()
18−run =
16+run :: () -> () -> IO ()
17+run () () =
1918 do reporter <- Terminal.create
2019 void $ Task.run reporter $
2120 do summary <- Project.getRoot
ui/terminal/src/Develop.hs+13−5
@@ -1,6 +1,9 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Develop (run) where
2+module Develop
3+ ( Flags(..)
4+ , run
5+ )
6+ where
47
58import Control.Applicative ((<|>))
69import Control.Concurrent (threadDelay)
@@ -16,7 +19,6 @@ import Snap.Util.FileServe
1619import qualified Text.Blaze.Html5 as H
1720import qualified Text.Blaze.Html.Renderer.Utf8 as Blaze
1821
19−import qualified CommandLine.Args as Args
2022import qualified Develop.Compile as Compile
2123import qualified Develop.Generate.Help as Generate
2224import qualified Develop.Generate.Index as Index
@@ -28,8 +30,14 @@ import qualified Develop.StaticFiles as StaticFiles
2830-- RUN THE DEV SERVER
2931
3032
31−run :: Args.DevFlags -> IO ()
32−run (Args.DevFlags maybePort) =
33+data Flags =
34+ Flags
35+ { _port :: Maybe Int
36+ }
37+
38+
39+run :: () -> Flags -> IO ()
40+run () (Flags maybePort) =
3341 -- TODO get `elm reactor` running again
3442 if True then
3543 putStrLn $
ui/terminal/src/Diff.hs+2−2
@@ -13,7 +13,7 @@ import qualified Reporting.Progress.Terminal as Terminal
1313-- RUN
1414
1515
16−run :: Diff.Args -> IO ()
17−run args =
16+run :: Diff.Args -> () -> IO ()
17+run args () =
1818 do reporter <- Terminal.create
1919 void $ Task.run reporter $ Diff.diff args
ui/terminal/src/Install.hs+2−3
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21module Install (run) where
32
43
@@ -14,8 +13,8 @@ import qualified Reporting.Progress.Terminal as Terminal
1413-- RUN
1514
1615
17−run :: Pkg.Name -> IO ()
18−run pkg =
16+run :: Pkg.Name -> () -> IO ()
17+run pkg () =
1918 do reporter <- Terminal.create
2019 void $ Task.run reporter $
2120 Install.install pkg
ui/terminal/src/Make.hs+18−9
@@ -1,23 +1,32 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Make (run) where
1+module Make
2+ ( Flags(..)
3+ , run
4+ )
5+ where
36
47
58import Control.Monad (void)
69
710import qualified Elm.Compiler.Objects as Obj
811import qualified Elm.Project as Project
9−import qualified Elm.Project.Flags as Flags
12+import qualified Generate.Output as Output
1013import qualified Reporting.Task as Task
1114import qualified Reporting.Progress.Terminal as Terminal
1215
13−import qualified CommandLine.Args as Args
14−
1516
1617
1718-- RUN
1819
1920
20−run :: [FilePath] -> Args.MakeFlags -> IO ()
21+data Flags =
22+ Flags
23+ { _warn :: Bool
24+ , _debug :: Bool
25+ , _output :: Maybe Output.Output
26+ }
27+
28+
29+run :: [FilePath] -> Flags -> IO ()
2130run paths flags =
2231 do reporter <- Terminal.create
2332 void $ Task.run reporter $
@@ -26,10 +35,10 @@ run paths flags =
2635
2736
2837-- TODO figure out --warn flag
29−toOptions :: Args.MakeFlags -> Flags.Options
30−toOptions (Args.MakeFlags _warn debug output) =
38+toOptions :: Flags -> Output.Options
39+toOptions (Flags warn debug output) =
3140 let
3241 mode = if debug then Obj.Debug else Obj.Prod
3342 target = if False then Obj.Server else Obj.Client
3443 in
35− Flags.Options mode target output
44+ Output.Options warn mode target output
ui/terminal/src/Publish.hs+2−3
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -Wall #-}
21module Publish (run) where
32
43
@@ -14,8 +13,8 @@ import qualified Reporting.Progress.Terminal as Terminal
1413-- RUN
1514
1615
17−run :: IO ()
18−run =
16+run :: () -> () -> IO ()
17+run () () =
1918 do reporter <- Terminal.create
2019 void $ Task.run reporter $
2120 do summary <- Project.getRoot
ui/terminal/src/Repl.hs+13−12
@@ -1,6 +1,9 @@
1−{-# OPTIONS_GHC -Wall #-}
21{-# LANGUAGE OverloadedStrings #-}
3−module Repl where
2+module Repl
3+ ( Flags(..)
4+ , run
5+ )
6+ where
47
58
69import Prelude hiding (lines, read)
@@ -8,7 +11,6 @@ import Control.Applicative ((<|>))
811import Control.Monad.RWS (lift, liftIO)
912import qualified Control.Monad.RWS as RWS
1013import qualified Data.ByteString.Builder as B
11−import qualified Data.ByteString.Char8 as BS
1214import qualified Data.ByteString.Lazy as LBS
1315import qualified Data.List as List
1416import qualified Data.Map as Map
@@ -31,15 +33,19 @@ import qualified Elm.Utils as Elm
3133import qualified Reporting.Task as Task
3234import qualified Reporting.Progress.Repl as Repl
3335
34−import qualified CommandLine.Args as Args
35−
3636
3737
3838-- RUN
3939
4040
41−run :: Args.ReplFlags -> IO ()
42−run (Args.ReplFlags maybeAlternateInterpreter) =
41+data Flags =
42+ Flags
43+ { _interpreter :: Maybe FilePath
44+ }
45+
46+
47+run :: () -> Flags -> IO ()
48+run () (Flags maybeAlternateInterpreter) =
4349 do interpreter <- getInterpreter maybeAlternateInterpreter
4450 _ <- Project.getRootWithReplFallback
4551 putStrLn welcomeMessage
@@ -131,11 +137,6 @@ eval input =
131137 report "I cannot handle port declarations."
132138
133139
134−toUtf8 :: String -> BS.ByteString
135−toUtf8 string =
136− LBS.toStrict (B.toLazyByteString (B.stringUtf8 string))
137−
138−
139140report :: String -> Runner (Maybe a)
140141report msg =
141142 do liftIO (putStrLn msg)