summaryrefslogtreecommitdiff
path: root/haskell/app
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-18 00:02:33 +0200
committerJulien Dessaux2023-07-18 00:02:33 +0200
commit4af96da5670566c111fa5c7dac9572eaac021a4b (patch)
tree74ae00fb63e087437bc3a62152d4b7fecf8c039e /haskell/app
parent[haskell] Trigger a program restart when the api client encounters a server r... (diff)
downloadspacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.tar.gz
spacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.tar.bz2
spacetraders-4af96da5670566c111fa5c7dac9572eaac021a4b.zip
[haskell] Refactored everything with a ReaderT pattern
Diffstat (limited to '')
-rw-r--r--haskell/app/Main.hs25
1 files changed, 20 insertions, 5 deletions
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