From 67447ac23b34e972a3ff9a3bc07b7eb52aa70fbb Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Fri, 27 Sep 2024 21:18:29 +0200 Subject: [PATCH] Support running the dependency runner from the command line Will fail currently --- byg/src/DependencyRunner.hs | 6 +++--- byg/src/Main.hs | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/byg/src/DependencyRunner.hs b/byg/src/DependencyRunner.hs index f014bcf..d46cade 100644 --- a/byg/src/DependencyRunner.hs +++ b/byg/src/DependencyRunner.hs @@ -1,7 +1,7 @@ module DependencyRunner ( DepRunM , runDeps - , runDepRunM + , runDepRunMIO ) where import Types (Value(..), Valuable(..)) @@ -19,8 +19,8 @@ newtype DepRunM a = DepRunM { unDepRunM :: StateT (Map Int Value) IO a } runDeps :: [Dependency] -> DepRunM () runDeps = mapM_ runDep -runDepRunM :: DepRunM a -> IO a -runDepRunM m = evalStateT (unDepRunM m) M.empty +runDepRunMIO :: DepRunM a -> IO a +runDepRunMIO m = evalStateT (unDepRunM m) M.empty runDep :: Dependency -> DepRunM () runDep (Dependency a action b) = do diff --git a/byg/src/Main.hs b/byg/src/Main.hs index 40ab697..6002d14 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -4,7 +4,9 @@ module Main where import Types.Dependency (Dependency, formatDependencyTrees) import DependencyGenerator (evalDepGenM) import SiteGenerator (generateSite) +import DependencyRunner (runDeps, runDepRunMIO) +import System.Environment (getArgs) import qualified Data.Text.IO as T import Language.Haskell.TH.Syntax (lift) @@ -12,4 +14,12 @@ dependencies :: [Dependency] dependencies = $(lift (evalDepGenM generateSite)) 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"