summaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs27
1 files changed, 15 insertions, 12 deletions
diff --git a/Main.hs b/Main.hs
index 1d668d3..df2c41b 100644
--- a/Main.hs
+++ b/Main.hs
@@ -22,30 +22,33 @@ r :: IO ()
r = main
dispatch :: Dispatch
-dispatch cmd sendMessage env@(Env state conf) =
- let commands = [
+dispatch msg sendMessage env@(Env state conf) = dispatch' msg
+ where
+ dispatch' ('!':_) =
+ case cmdGet msg commands of
+ Just (Cmd _ _ cmdAction) -> do
+ cmdAction state
+ return (env)
+ Nothing -> return (env)
+ dispatch' _ = return (env)
+ commands = [
Cmd "!h" "Prints help" printHelp,
Cmd "!i" "Prints infos" printInfos,
Cmd "!p" "Prints current state" printState,
Cmd "!s" "Stores current state to file" storeState,
Cmd "!q" "quits" quit
]
- printHelp _ = printHelp' commands
+ printHelp _ = printHelp' commands
where printHelp' = sendMessage . concat . showL
- printInfos _ = do
+ printInfos _ = do
sendMessage $ (envGet "name" env)
++ " " ++ (envGet "version" env)
++ " (try !h)"
- printState = sendMessage . show
- storeState state = do
+ printState = sendMessage . show
+ storeState state = do
sendMessage "Storing current state"
stateSave (envGet "databaseFile" env) state
- quit state = do
+ quit state = do
sendMessage "Good bye"
stateSave (envGet "databaseFile" env) state
exitWith ExitSuccess
-
- in case cmdGet ("!" ++ cmd) commands of
- Just (Cmd _ _ cmdAction) -> cmdAction state
- Nothing -> return ()
-