From 4af96da5670566c111fa5c7dac9572eaac021a4b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 18 Jul 2023 00:02:33 +0200 Subject: [haskell] Refactored everything with a ReaderT pattern --- haskell/app/Main.hs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'haskell/app/Main.hs') diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index e22988c..1b2ccec 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -3,19 +3,34 @@ module Main (main) where import Control.Exception +import System.Environment +import System.Posix.Process import SpaceTraders import SpaceTraders.Automation.Init import SpaceTraders.APIClient.Agent(myAgent) +import SpaceTraders.APIClient.Client +import SpaceTraders.APIClient.Ships import SpaceTraders.APIClient.Systems main :: IO () main = do - config <- initST - ma <- runSpaceTradersT myAgent config - print ma - s <- listSystems (token config) (conn config) + env <- initST + ma <- runSpaceTradersT myAgent env + case ma of + Left (APIResetHappened _) -> do + p <- getExecutablePath + a <- getArgs + e <- getEnvironment + executeFile p False a (Just e) + Left e -> throwIO e + Right ma' -> print ma' + s <- runSpaceTradersT listSystems env case s of Left e -> throwIO e Right s' -> print $ length s' - deinitST config + ships <- runSpaceTradersT listShips env + case ships of + Left e -> throwIO e + Right s' -> print $ s' + deinitST env -- cgit v1.2.3