Extending command line options with Haskell Snap

I have an acidic backend that complements my site. It works in its own process, and my network web server needs an IP address to connect to it. For debugging and deployment purposes, I would like to pass the IP address as a command line argument when starting my compiled application. This IP address will be available inside the monad SnapletInitwhere the acid state handler is called.

How can I extend the command line options in Snap for this?

Ideally, I would like something like that.

./app -ip 192.168.0.2 -p 8080 -e prod +RTS -I0 -A4M -qg1

Then apply it like this.

app :: SnapletInit App App
app = makeSnaplet "app" "Snapplication" Nothing $ do
    ip <- getConfig "ip"
    d <- nestSnaplet "acid" acid $ acidInitRemote ip
    return $ App d
+3
source share
3 answers

Acid State, IP . Snap , , , -e . , -e prod snaplet/acidstate/prod.conf, -e -e devel snaplet/acidstate/devel.conf. , .

:

initStripe :: SnapletInit b StripeState
initStripe = makeSnaplet "stripe" "Stripe credit card payment" Nothing $ do
  config <- getSnapletUserConfig

  (stripeState, errors) <- runWriterT $ do
    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   <- Just . maybe V20110915d OtherVersion <$> liftIO (C.lookup config "version")
    let caFilePath = Just "" -- This is unused by Stripe but vestigial in the Haskell library.

    return $ StripeState <$> (StripeConfig <$> (SecretKey <$> secretKey) <*> caFilePath <*> version) <*> (PublicKey <$> publicKey) <*> clientId
  return $ fromMaybe (error $ intercalate "\n" errors) stripeState
+1

getEnv, lookupEnv getArgs System.Environment

ENV.

0

All Articles