author | unc0rr |
Wed, 23 Feb 2011 18:38:11 +0300 | |
changeset 4957 | 3684faf5b3d1 |
parent 4932 | f11d80bac7ed |
child 4975 | 31da8979e5b1 |
permissions | -rw-r--r-- |
4932 | 1 |
{-# LANGUAGE CPP #-} |
1804 | 2 |
module Opts |
3 |
( |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
4 |
getOpts, |
1804 | 5 |
) where |
6 |
||
4905 | 7 |
import System.Environment |
1804 | 8 |
import System.Console.GetOpt |
4932 | 9 |
import Data.Maybe ( fromMaybe ) |
10 |
------------------- |
|
1804 | 11 |
import CoreTypes |
12 |
import Utils |
|
13 |
||
14 |
options :: [OptDescr (ServerInfo -> ServerInfo)] |
|
15 |
options = [ |
|
4932 | 16 |
Option "p" ["port"] (ReqArg readListenPort "PORT") "listen on PORT", |
17 |
Option "d" ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)" |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
18 |
] |
1804 | 19 |
|
4932 | 20 |
readListenPort |
21 |
, readDedicated |
|
22 |
:: String -> ServerInfo -> ServerInfo |
|
23 |
||
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 |
|
4932 | 29 |
readDedicated str opts = opts{isDedicated = readDed} |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
30 |
where |
4932 | 31 |
readDed = fromMaybe True (maybeRead str :: Maybe Bool) |
1804 | 32 |
|
33 |
getOpts :: ServerInfo -> IO ServerInfo |
|
34 |
getOpts opts = do |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
35 |
args <- getArgs |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
36 |
case getOpt Permute options args of |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
37 |
(o, [], []) -> return $ foldr ($) opts o |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
1964
diff
changeset
|
38 |
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options)) |
2966 | 39 |
where header = "Usage: hedgewars-server [OPTION...]" |