-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
39 lines (34 loc) · 1.17 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Main where
import Data.List (intercalate)
import System.Environment (getArgs, getProgName)
import qualified HawkClient as Hawk
import qualified HawkServer as Hawk
import qualified BewitClient as Bewit
import qualified BewitServer as Bewit
import qualified OzClient as Oz
import qualified OzServer as Oz
main :: IO ()
main = do
prog <- getProgName
args <- getArgs
case dispatch prog of
Just act -> act
Nothing -> case args of
(arg:_) -> case dispatch arg of
Just act -> act
Nothing -> usage prog
_ -> usage prog
dispatch :: String -> Maybe (IO ())
dispatch "hawk-server" = Just Hawk.serverMain
dispatch "hawk-client" = Just Hawk.clientMain
dispatch "bewit-server" = Just Bewit.serverMain
dispatch "bewit-client" = Just Bewit.clientMain
dispatch "oz-server" = Just Oz.serverMain
dispatch "oz-client" = Just Oz.clientMain
dispatch _ = Nothing
usage :: String -> IO ()
usage prog = putStrLn $ "Usage: " ++ prog ++ " [ " ++ progs ++ " ]"
where
progs = intercalate " | " [ p ++ "-" ++ c | p <- ps, c <- cs]
ps = ["hawk", "bewit", "oz"]
cs = ["client", "server"]