author | koda |
Sun, 16 Jan 2011 03:39:54 +0100 | |
branch | 0.9.14 |
changeset 4310 | 4613b178d45c |
parent 4242 | 5e3c5fe2cb14 |
child 4295 | 1f5604cd99be |
child 4334 | 82cfbbab73da |
permissions | -rw-r--r-- |
1804 | 1 |
module Opts |
2 |
( |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
3 |
getOpts, |
1804 | 4 |
) where |
5 |
||
4242 | 6 |
import System |
1804 | 7 |
import System.Console.GetOpt |
8 |
import Network |
|
9 |
import Data.Maybe ( fromMaybe ) |
|
10 |
import CoreTypes |
|
11 |
import Utils |
|
12 |
||
13 |
options :: [OptDescr (ServerInfo -> ServerInfo)] |
|
14 |
options = [ |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
15 |
Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT", |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
16 |
Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
17 |
] |
1804 | 18 |
|
1832 | 19 |
readListenPort, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
20 |
readDedicated, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
21 |
readDbLogin, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
22 |
readDbPassword, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
23 |
readDbHost :: String -> ServerInfo -> ServerInfo |
1832 | 24 |
|
1804 | 25 |
readListenPort str opts = opts{listenPort = readPort} |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
26 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
27 |
readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer) |
1804 | 28 |
|
29 |
readDedicated str opts = opts{isDedicated = readDedicated} |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
30 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
31 |
readDedicated = fromMaybe True (maybeRead str :: Maybe Bool) |
1804 | 32 |
|
4242 | 33 |
readDbLogin str opts = opts{dbLogin = str} |
34 |
readDbPassword str opts = opts{dbPassword = str} |
|
35 |
readDbHost str opts = opts{dbHost = str} |
|
1804 | 36 |
|
37 |
getOpts :: ServerInfo -> IO ServerInfo |
|
38 |
getOpts opts = do |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
39 |
args <- getArgs |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
40 |
case getOpt Permute options args of |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
41 |
(o, [], []) -> return $ foldr ($) opts o |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
42 |
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options)) |
2966 | 43 |
where header = "Usage: hedgewars-server [OPTION...]" |