@@ -1,4 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE FlexibleContexts #-}
23module Obelisk.Command.Run where
34
45import qualified Control.Exception as E
@@ -6,7 +7,9 @@ import Control.Monad
67import Data.Either
78import Data.List
89import Data.Maybe
10+import Control.Monad.IO.Class (liftIO)
911import Data.Monoid
12+import qualified Data.Text as T
1013import Data.List.NonEmpty as NE
1114import Distribution.Utils.Generic (withUTF8FileContents)
1215import Distribution.PackageDescription.Parse (parseGenericPackageDescription, ParseResult(..))
@@ -20,20 +23,24 @@ import System.FilePath
2023import System.IO.Temp (withSystemTempDirectory)
2124import System.Process (callCommand)
2225
23−run :: IO ()
26+import Obelisk.App (ObeliskT)
27+import Obelisk.CLI (putLog, failWith, Severity(..))
28+
29+-- NOTE: `run` is not polymorphic like the rest because we use StaticPtr to invoke it.
30+run :: ObeliskT IO ()
2431run = do
25− freePort <- getFreePort
26− pkgs <- getLocalPkgs
27− (pkgDirErrs, hsSrcDirs) <- fmap partitionEithers $ forM pkgs $ \pkg -> do
32+ freePort <- liftIO getFreePort
33+ pkgs <- liftIO getLocalPkgs
34+ (pkgDirErrs, hsSrcDirs) <- liftIO $ fmap partitionEithers $ forM pkgs $ \pkg -> do
2835 let cabalFp = pkg </> pkg <.> "cabal"
2936 xs <- parseHsSrcDir cabalFp
3037 return $ case xs of
3138 Nothing -> Left pkg
3239 Just hsSrcDirs -> Right $ toList $ fmap (pkg </>) hsSrcDirs
3340 when (null hsSrcDirs) $
34− fail $ "No valid pkgs found in " <> intercalate ", " pkgs
41+ failWith $ T.pack $ "No valid pkgs found in " <> intercalate ", " pkgs
3542 when (not (null pkgDirErrs)) $
36− putStrLn $ "Failed to find pkgs in " <> intercalate ", " pkgDirErrs
43+ putLog Warning $ T.pack $ "Failed to find pkgs in " <> intercalate ", " pkgDirErrs
3744 let dotGhci = unlines
3845 [ ":set args --quiet --port " <> show freePort
3946 , ":set -i" <> intercalate ":" (mconcat hsSrcDirs)
@@ -50,8 +57,9 @@ run = do
5057 ]
5158 withSystemTempDirectory "ob-ghci" $ \fp -> do
5259 let dotGhciPath = fp </> ".ghci"
53− writeFile dotGhciPath dotGhci
54− runDev dotGhciPath $ Just testCmd
60+ liftIO $ do
61+ writeFile dotGhciPath dotGhci
62+ runDev dotGhciPath $ Just testCmd
5563
5664-- | Relative paths to local packages of an obelisk project
5765-- TODO a way to query this