-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.hs
30 lines (22 loc) · 898 Bytes
/
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
module Main where
import Debug.Trace
import Network
import System (getArgs)
import System.Console.GetOpt
import Server
defaultPort = 9000
main = do
args <- getArgs
let (flags, nonOpts, msgs) = getOpt Permute options args
if null flags
then trace ("Starting server on default port (" ++ (show defaultPort) ++ ").") $ server (PortNumber (fromIntegral defaultPort))
else server (head flags)
options :: [OptDescr PortID]
options = [ Option ['p'] ["port"]
(ReqArg makePortNumber "port number")
"server port number" ]
makePortNumber :: String -> PortID
makePortNumber s =
case reads s :: [(Int, String)] of
(p, _):rest -> trace ("Starting server on port " ++ (show p)) $ PortNumber (fromIntegral p)
otherwise -> trace ("Error parsing port. Starting server on default port (" ++ (show defaultPort) ++ ").") $ PortNumber (fromIntegral defaultPort)