forked from nominolo/scion
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added handling of command line options;
added an option to set the TCP port to listen on; in absence of this option, made the server automatically determine a free port (using linear search)
- Loading branch information
Showing
4 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
module Main where | ||
|
||
import Scion | ||
import Scion.Server.Options | ||
import Scion.Server.Emacs | ||
|
||
main = runScion $ runServer | ||
main = do | ||
opts <- readOptions | ||
runScion $ runServer opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Scion.Server.Options where | ||
|
||
import System.Environment ( getArgs ) | ||
import System.Exit ( exitWith, ExitCode(..) ) | ||
import System.Console.GetOpt ( getOpt, usageInfo, ArgOrder(..), OptDescr(..), ArgDescr(..) ) | ||
|
||
data ServerPort = AutoPort | FixedPort Int | ||
|
||
data ServerOptions = ServerOptions | ||
{ optPort :: ServerPort | ||
, optLogLevel :: Int | ||
} | ||
|
||
defaultOptions = ServerOptions | ||
{ optPort = AutoPort | ||
, optLogLevel = 2 | ||
} | ||
|
||
readOptions :: IO ServerOptions | ||
readOptions = do | ||
argv <- getArgs | ||
case getOpt Permute options argv of | ||
(o, n, [] ) -> return $ foldl (flip id) defaultOptions o | ||
(_, _, errs) -> putStr (concat errs ++ usageInfo header options) >> exitWith (ExitFailure 1) | ||
where | ||
header = "Command line options:" | ||
|
||
|
||
options :: [OptDescr (ServerOptions -> ServerOptions)] | ||
options = | ||
[ Option ['p'] ["port"] | ||
(ReqArg (\p opts -> opts { optPort = FixedPort (read p) }) "<port-number>") | ||
"port number to listen on" | ||
, Option | ||
['v'] ["verbosity"] | ||
(ReqArg (\v opts -> opts { optLogLevel = read v }) "<number>") | ||
"log level (not yet implemented)" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters