th-env 0.1.0.3 → 0.1.1
raw patch · 5 files changed
+28/−9 lines, 5 files
Files
- CHANGELOG.md +8/−0
- README.lhs +1/−1
- README.md +1/−1
- src/Language/Haskell/TH/Env.hs +14/−3
- th-env.cabal +4/−4
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Changelog +## [0.1.1] - 2022-05-23++## Added++- [#6](https://github.com/dzhus/th-env/pull/6) Add `envQ'` variant+ that requires the environment variable to be set at compilation time+ ## [0.1.0.3] - 2021-11-05 ### Changed@@ -20,6 +27,7 @@ ## [0.1.0.0] - 2019-05-01 +[0.1.1]: https://github.com/dzhus/th-env/compare/0.1.0.3...0.1.1 [0.1.0.3]: https://github.com/dzhus/th-env/compare/0.1.0.2...0.1.0.3 [0.1.0.2]: https://github.com/dzhus/th-env/compare/0.1.0.1...0.1.0.2 [0.1.0.1]: https://github.com/dzhus/th-env/compare/0.1.0.0...0.1.0.1
README.lhs view
@@ -10,5 +10,5 @@ import Language.Haskell.TH.Env main :: IO ()-main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER")+main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER") ++ " in " ++ $$(envQ' "PWD") ```
README.md view
@@ -10,5 +10,5 @@ import Language.Haskell.TH.Env main :: IO ()-main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER")+main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER") ++ " in " ++ $$(envQ' "PWD") ```
src/Language/Haskell/TH/Env.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TemplateHaskellQuotes #-} -module Language.Haskell.TH.Env (envQ)+module Language.Haskell.TH.Env (envQ, envQ') where @@ -12,7 +12,7 @@ import System.Environment -- | Produce a typed expression with the current value of an--- environment variable.+-- environment variable, or Nothing if it's not set. envQ :: IsString a => String -- ^ Environment variable name.@@ -21,3 +21,14 @@ runIO (lookupEnv name) >>= \case Just v -> fromCode $ toCode [|| Just (fromString v) ||] Nothing -> fromCode $ toCode [|| Nothing ||]++-- | Produce a typed expression with the current value of an+-- environment variable. Fail if it's not set.+envQ' :: IsString a+ => String+ -- ^ Environment variable name.+ -> SpliceQ a+envQ' name = liftSplice $+ runIO (lookupEnv name) >>= \case+ Just v -> fromCode $ toCode [|| fromString v ||]+ Nothing -> fail $ "Environment variable " ++ name ++ " is not set"
th-env.cabal view
@@ -4,12 +4,12 @@ -- -- see: https://github.com/sol/hpack ----- hash: 77684b3ed7955003a3cc45577f9c5d9f7a3b95b0088f665dba6b29b46eb4a57f+-- hash: 95226380269cc2dc702ac016f5a227875b5724dd211f6548ebc31dbe2a112191 name: th-env-version: 0.1.0.3-synopsis: Template Haskell splice that expands to an environment variable-description: TH splice that expands to an environment variable value. Can be used to embed build-time parameters in your application.+version: 0.1.1+synopsis: Template Haskell splices that expand to an environment variable+description: TH splices that expand to an environment variable value. Can be used to embed build-time parameters in your application. category: Template Haskell homepage: https://github.com/dzhus/th-env#readme bug-reports: https://github.com/dzhus/th-env/issues