Extending command line options with Haskell Snap -


i have acid-state backend complements snap website. running in own process , snap web server requires ip address connect it. debugging , deployment purposes able pass in ip address command line argument when running compiled snap application. ip address accessible inside snapletinit monad acid state handler gets called.

how can extend command line parameter system in snap account this?

ideally, i'd like.

./app -ip 192.168.0.2 -p 8080 -e prod +rts -i0 -a4m -qg1 

then apply this.

app :: snapletinit app app app = makesnaplet "app" "snapplication" nothing $     ip <- getconfig "ip"     d <- nestsnaplet "acid" acid $ acidinitremote ip     return $ app d 

i recommend changing acid state snaplet read it's ip config instead of command line. configs in snap set it'll load whatever pass -e argument on command line. example, starting -e prod load snaplet/acidstate/prod.conf , starting no -e or -e devel load snaplet/acidstate/devel.conf. helps keep environmental settings instead of allowing possible combination of command line flags.

here's an example 1 of snaplets:

initstripe :: snapletinit b stripestate initstripe = makesnaplet "stripe" "stripe credit card payment" nothing $   config <- getsnapletuserconfig    (stripestate, errors) <- runwritert $     secretkey <- logerr "must specify strip secret key"  $ c.lookup config "secret_key"     publickey <- logerr "must specify strip public key"  $ c.lookup config "public_key"     clientid  <- logerr "must specify strip client id"   $ c.lookup config "client_id"     version   <- . maybe v20110915d otherversion <$> liftio (c.lookup config "version")     let cafilepath = "" -- unused stripe vestigial in haskell library.      return $ stripestate <$> (stripeconfig <$> (secretkey <$> secretkey) <*> cafilepath <*> version) <*> (publickey <$> publickey) <*> clientid   return $ frommaybe (error $ intercalate "\n" errors) stripestate 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -