netserver/Opts.hs
changeset 1757 3aa7d21baca1
parent 1492 2da1fe033f23
equal deleted inserted replaced
1756:98cf15b23985 1757:3aa7d21baca1
    12 
    12 
    13 
    13 
    14 options :: [OptDescr (ServerInfo -> ServerInfo)]
    14 options :: [OptDescr (ServerInfo -> ServerInfo)]
    15 options = [
    15 options = [
    16 	Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
    16 	Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT",
    17 	Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)"
    17 	Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)",
       
    18 	Option []    ["password"] (ReqArg readPassword "STRING") "admin password"
    18 	]
    19 	]
    19 
    20 
    20 readListenPort, readDedicated :: String -> ServerInfo -> ServerInfo
    21 readListenPort, readDedicated, readPassword :: String -> ServerInfo -> ServerInfo
    21 readListenPort str opts = opts{listenPort = readPort}
    22 readListenPort str opts = opts{listenPort = readPort}
    22 	where
    23 	where
    23 		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
    24 		readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer)
    24 
    25 
    25 readDedicated str opts = opts{isDedicated = readDedicated}
    26 readDedicated str opts = opts{isDedicated = readDedicated}
    26 	where
    27 	where
    27 		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)
    28 		readDedicated = fromMaybe True (maybeRead str :: Maybe Bool)
    28 
    29 
       
    30 readPassword str opts = opts{adminPassword = str}
       
    31 
    29 getOpts :: ServerInfo -> IO ServerInfo
    32 getOpts :: ServerInfo -> IO ServerInfo
    30 getOpts opts = do
    33 getOpts opts = do
    31 	args <- getArgs
    34 	args <- getArgs
    32 	case getOpt Permute options args of
    35 	case getOpt Permute options args of
    33 		(o, [], []) -> return $ foldr ($) opts o
    36 		(o, [], []) -> return $ foldr ($) opts o