author | unc0rr |
Sat, 17 Nov 2012 00:01:06 +0400 | |
branch | physfslayer |
changeset 8034 | fc032c0f7b23 |
parent 5210 | a5329e52a71b |
child 10460 | 8dcea9087d75 |
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 |
||
4989 | 14 |
options :: [OptDescr (ServerInfo -> ServerInfo)] |
1804 | 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 |
|
4989 | 22 |
:: String -> ServerInfo -> ServerInfo |
4932 | 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 |
|
4989 | 33 |
getOpts :: ServerInfo -> IO ServerInfo |
1804 | 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 |
5210 | 37 |
(o, [], []) -> return $ foldr ($) opts{runArgs = args} o |
2867
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...]" |