Support running the dependency runner from the command line

Will fail currently
This commit is contained in:
Niels G. W. Serup 2024-09-27 21:18:29 +02:00
parent d3b32398b5
commit 67447ac23b
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
2 changed files with 14 additions and 4 deletions

View File

@ -1,7 +1,7 @@
module DependencyRunner module DependencyRunner
( DepRunM ( DepRunM
, runDeps , runDeps
, runDepRunM , runDepRunMIO
) where ) where
import Types (Value(..), Valuable(..)) import Types (Value(..), Valuable(..))
@ -19,8 +19,8 @@ newtype DepRunM a = DepRunM { unDepRunM :: StateT (Map Int Value) IO a }
runDeps :: [Dependency] -> DepRunM () runDeps :: [Dependency] -> DepRunM ()
runDeps = mapM_ runDep runDeps = mapM_ runDep
runDepRunM :: DepRunM a -> IO a runDepRunMIO :: DepRunM a -> IO a
runDepRunM m = evalStateT (unDepRunM m) M.empty runDepRunMIO m = evalStateT (unDepRunM m) M.empty
runDep :: Dependency -> DepRunM () runDep :: Dependency -> DepRunM ()
runDep (Dependency a action b) = do runDep (Dependency a action b) = do

View File

@ -4,7 +4,9 @@ module Main where
import Types.Dependency (Dependency, formatDependencyTrees) import Types.Dependency (Dependency, formatDependencyTrees)
import DependencyGenerator (evalDepGenM) import DependencyGenerator (evalDepGenM)
import SiteGenerator (generateSite) import SiteGenerator (generateSite)
import DependencyRunner (runDeps, runDepRunMIO)
import System.Environment (getArgs)
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import Language.Haskell.TH.Syntax (lift) import Language.Haskell.TH.Syntax (lift)
@ -12,4 +14,12 @@ dependencies :: [Dependency]
dependencies = $(lift (evalDepGenM generateSite)) dependencies = $(lift (evalDepGenM generateSite))
main :: IO () main :: IO ()
main = T.putStr $ formatDependencyTrees dependencies main = do
args <- getArgs
case args of
["run"] ->
runDepRunMIO $ runDeps dependencies
["tree"] ->
T.putStr $ formatDependencyTrees dependencies
_ ->
error "unexpected arguments"