Permalink
Browse files

Refactor to preserve commandLineConfig's interface

  • Loading branch information...
1 parent 10c873e commit c9c146a353581a20d52493406843f7d5e22d965c @mightybyte mightybyte committed Apr 18, 2012
Showing with 20 additions and 5 deletions.
  1. +1 −2 src/Snap/Http/Server.hs
  2. +19 −3 src/Snap/Http/Server/Config.hs
@@ -150,8 +150,7 @@ compress conf = if fromJust $ getCompression conf then withCompression else id
-- 'commandLineConfig'. This function never returns; to shut down the HTTP
-- server, kill the controlling thread.
quickHttpServe :: Snap () -> IO ()
-quickHttpServe m = commandLineConfig (const []) emptyConfig >>=
- \c -> httpServe c m
+quickHttpServe m = commandLineConfig emptyConfig >>= \c -> httpServe c m
------------------------------------------------------------------------------
@@ -537,14 +537,30 @@ defaultErrorHandler e = do
--
-- On Unix systems, the locale is read from the @LANG@ environment variable.
commandLineConfig :: MonadSnap m
- => (a -> [OptDescr (Maybe a)])
- -> Config m a
+ => Config m a
-- ^ default configuration. This is combined with
-- 'defaultConfig' to obtain default values to use if the
-- given parameter is specified on the command line. Usually
-- it is fine to use 'emptyConfig' here.
-> IO (Config m a)
-commandLineConfig otherOpts defaults = do
+commandLineConfig = commandLineConfig' (const [])
+
+
+------------------------------------------------------------------------------
+-- | Returns a 'Config' obtained from parsing the options specified on the
+-- command-line. This variant allows you to specify your own options used to
+-- set the other field.
+--
+-- On Unix systems, the locale is read from the @LANG@ environment variable.
+commandLineConfig' :: MonadSnap m
+ => (a -> [OptDescr (Maybe a)])
+ -> Config m a
+ -- ^ default configuration. This is combined with
+ -- 'defaultConfig' to obtain default values to use if the
+ -- given parameter is specified on the command line. Usually
+ -- it is fine to use 'emptyConfig' here.
+ -> IO (Config m a)
+commandLineConfig' otherOpts defaults = do
args <- getArgs
prog <- getProgName

0 comments on commit c9c146a

Please sign in to comment.