1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Pull port and host from environment

This commit is contained in:
Timothy Clem 2018-06-06 16:17:44 -07:00
parent 170cadfcbd
commit 19f30f33cc
2 changed files with 16 additions and 0 deletions

View File

@ -153,6 +153,7 @@ library
, Semantic.CLI
, Semantic.Diff
, Semantic.Distribute
, Semantic.Env
, Semantic.Graph
, Semantic.IO
, Semantic.Log

15
src/Semantic/Env.hs Normal file
View File

@ -0,0 +1,15 @@
module Semantic.Env where
import Control.Monad.IO.Class
import Prologue
import System.Environment
import Text.Read (readMaybe)
envLookupHost :: MonadIO io => String -> String -> io String
envLookupHost defaultHost k = liftIO $ fromMaybe defaultHost <$> lookupEnv k
envLookupPort :: MonadIO io => Int -> String -> io Int
envLookupPort defaultPort k = liftIO $ parsePort <$> lookupEnv k
where parsePort x | Just s <- x
, Just p <- readMaybe s = p
| otherwise = defaultPort