Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Feb 3, 2025
1 parent 89491ad commit 6f7591d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ data Mode = Lenient | Strict

run :: [String] -> IO ()
run args = do
config <- loadConfig
runArgs@RunArgs{dir, lastOutput, queue} <- defaultRunArgs
HTTP.withServer dir (readMVar lastOutput) $ do
watchFiles dir queue $ do
mode <- newIORef Lenient
Input.watch stdin (dispatch mode queue) (emitEvent queue Done)
runWith runArgs {args}
runWith runArgs {config, args}
where
dispatch :: IORef Mode -> EventQueue -> Char -> IO ()
dispatch mode queue = \ case
Expand All @@ -88,7 +89,7 @@ defaultRunArgs = do
queue <- newQueue
lastOutput <- newMVar (Trigger.Success, "", [])
return RunArgs {
ignoreConfig = False
config = defaultConfig
, dir = ""
, args = []
, lastOutput = lastOutput
Expand All @@ -98,7 +99,7 @@ defaultRunArgs = do
}

data RunArgs = RunArgs {
ignoreConfig :: Bool
config :: Config
, dir :: FilePath
, args :: [String]
, lastOutput :: MVar (Result, String, [Diagnostic])
Expand All @@ -109,9 +110,6 @@ data RunArgs = RunArgs {

runWith :: RunArgs -> IO ()
runWith RunArgs {..} = do
config <- case ignoreConfig of
False -> loadConfig
True -> return defaultConfig
cleanup <- newIORef pass
let
runCleanupAction :: IO ()
Expand Down
8 changes: 4 additions & 4 deletions test/RunSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import qualified Run
defaultRunArgs :: IO RunArgs
defaultRunArgs = do
args <- Run.defaultRunArgs
return args { ignoreConfig = True, sessionConfig = args.sessionConfig { configEcho = silent } }
return args { sessionConfig = args.sessionConfig { configEcho = silent } }

spec :: Spec
spec = do
Expand All @@ -28,7 +28,7 @@ spec = do
RunArgs{..} <- defaultRunArgs
let
runArgs = RunArgs {
withSession = \ config sessionArgs action -> withSession config sessionArgs $ \ session -> do
withSession = \ conf sessionArgs action -> withSession conf sessionArgs $ \ session -> do
spy sessionArgs
action session <* emitEvent runArgs.queue Done
, ..
Expand All @@ -43,7 +43,7 @@ spec = do
RunArgs{..} <- defaultRunArgs
let
runArgs = RunArgs {
withSession = \ config sessionArgs action -> withSession config sessionArgs $ \ session -> do
withSession = \ conf sessionArgs action -> withSession conf sessionArgs $ \ session -> do
spy sessionArgs
action session <* emitEvent runArgs.queue Done
, ..
Expand All @@ -60,7 +60,7 @@ spec = do
RunArgs{..} <- defaultRunArgs
let
runArgs = RunArgs {
withSession = \ config sessionArgs action -> withSession config sessionArgs $ \ session -> do
withSession = \ conf sessionArgs action -> withSession conf sessionArgs $ \ session -> do
spy sessionArgs
nextEvent >>= emitEvent runArgs.queue
action session
Expand Down

0 comments on commit 6f7591d

Please sign in to comment.