Skip to content

Commit

Permalink
Added -p/--port option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jan 29, 2009
1 parent 7e0b5e0 commit 84aa2fc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Gitit/Config.hs
Expand Up @@ -32,16 +32,19 @@ import Control.Monad (liftM, foldM)
data Opt data Opt
= Help = Help
| ConfigFile FilePath | ConfigFile FilePath
| Port Int
| Version | Version
deriving (Eq) deriving (Eq)


flags :: [OptDescr Opt] flags :: [OptDescr Opt]
flags = flags =
[ Option ['h'] [] (NoArg Help) [ Option ['h'] ["help"] (NoArg Help)
"Print this help message" "Print this help message"
, Option ['v'] [] (NoArg Version) , Option ['v'] ["version"] (NoArg Version)
"Print version information" "Print version information"
, Option ['f'] [] (ReqArg ConfigFile "FILE") , Option ['p'] ["port"] (ReqArg (Port . read) "PORT")
"Specify port"
, Option ['f'] ["config-file"] (ReqArg ConfigFile "FILE")
"Specify configuration file" "Specify configuration file"
] ]


Expand All @@ -62,11 +65,12 @@ copyrightMessage = "\nCopyright (C) 2008 John MacFarlane\n" ++
"warranty, not even for merchantability or fitness for a particular purpose." "warranty, not even for merchantability or fitness for a particular purpose."


handleFlag :: Config -> Opt -> IO Config handleFlag :: Config -> Opt -> IO Config
handleFlag _ opt = do handleFlag conf opt = do
progname <- getProgName progname <- getProgName
case opt of case opt of
Help -> hPutStrLn stderr (usageInfo (usageHeader progname) flags) >> exitWith ExitSuccess Help -> hPutStrLn stderr (usageInfo (usageHeader progname) flags) >> exitWith ExitSuccess
Version -> hPutStrLn stderr (progname ++ " version " ++ _VERSION ++ copyrightMessage) >> exitWith ExitSuccess Version -> hPutStrLn stderr (progname ++ " version " ++ _VERSION ++ copyrightMessage) >> exitWith ExitSuccess
Port p -> return $ conf { portNumber = p }
ConfigFile f -> liftM read (readFile f) ConfigFile f -> liftM read (readFile f)


getConfigFromOpts :: IO Config getConfigFromOpts :: IO Config
Expand Down

0 comments on commit 84aa2fc

Please sign in to comment.