th-env-0.1.1/src/0000755000000000000000000000000013666023741011677 5ustar0000000000000000th-env-0.1.1/src/Language/0000755000000000000000000000000013666023741013422 5ustar0000000000000000th-env-0.1.1/src/Language/Haskell/0000755000000000000000000000000013666023741015005 5ustar0000000000000000th-env-0.1.1/src/Language/Haskell/TH/0000755000000000000000000000000014236530166015316 5ustar0000000000000000th-env-0.1.1/src/Language/Haskell/TH/Env.hs0000644000000000000000000000202114236530166016375 0ustar0000000000000000{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskellQuotes #-} module Language.Haskell.TH.Env (envQ, envQ') where import Data.String import Language.Haskell.TH import Language.Haskell.TH.Syntax.Compat import System.Environment -- | Produce a typed expression with the current value of an -- environment variable, or Nothing if it's not set. envQ :: IsString a => String -- ^ Environment variable name. -> SpliceQ (Maybe a) envQ name = liftSplice $ 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-0.1.1/README.lhs0000644000000000000000000000113214236530166012550 0ustar0000000000000000# th-env [![Build & test](https://github.com/dzhus/th-env/workflows/Build%20&%20test/badge.svg)](https://github.com/dzhus/th-env/actions) [![Hackage](https://img.shields.io/hackage/v/th-env.svg?colorB=5e5184&style=flat)](https://hackage.haskell.org/package/th-env) [![Hackage deps](https://img.shields.io/hackage-deps/v/th-env.svg)](http://packdeps.haskellers.com/feed?needle=th-env) ```haskell {-# LANGUAGE TemplateHaskell #-} import Data.Maybe import Language.Haskell.TH.Env main :: IO () main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER") ++ " in " ++ $$(envQ' "PWD") ``` th-env-0.1.1/CHANGELOG.md0000644000000000000000000000145214242772247012726 0ustar0000000000000000# 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 - [#2](https://github.com/dzhus/th-env/pull/2) GHC 9.x / `template-haskell-2.17` support ## [0.1.0.2] - 2020-06-03 ### Changed - Relaxed dependency version bounds ## [0.1.0.1] - 2020-02-21 ### Changed - Dependencies bump ## [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 [0.1.0.0]: https://github.com/dzhus/th-env/tree/0.1.0.0 th-env-0.1.1/README.md0000644000000000000000000000113214236530166012362 0ustar0000000000000000# th-env [![Build & test](https://github.com/dzhus/th-env/workflows/Build%20&%20test/badge.svg)](https://github.com/dzhus/th-env/actions) [![Hackage](https://img.shields.io/hackage/v/th-env.svg?colorB=5e5184&style=flat)](https://hackage.haskell.org/package/th-env) [![Hackage deps](https://img.shields.io/hackage-deps/v/th-env.svg)](http://packdeps.haskellers.com/feed?needle=th-env) ```haskell {-# LANGUAGE TemplateHaskell #-} import Data.Maybe import Language.Haskell.TH.Env main :: IO () main = print $ "Running app compiled by " ++ fromMaybe "?" $$(envQ "USER") ++ " in " ++ $$(envQ' "PWD") ``` th-env-0.1.1/LICENSE0000644000000000000000000000276113666023741012123 0ustar0000000000000000Copyright Dmitry Dzhus (c) 2019 All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Dmitry Dzhus nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. th-env-0.1.1/Setup.hs0000644000000000000000000000005613666023741012545 0ustar0000000000000000import Distribution.Simple main = defaultMain th-env-0.1.1/th-env.cabal0000644000000000000000000000255014236671352013300 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack -- -- hash: 95226380269cc2dc702ac016f5a227875b5724dd211f6548ebc31dbe2a112191 name: th-env 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 author: Dmitry Dzhus maintainer: dima@dzhus.org license: BSD3 license-file: LICENSE build-type: Simple extra-source-files: CHANGELOG.md README.md source-repository head type: git location: https://github.com/dzhus/th-env library exposed-modules: Language.Haskell.TH.Env other-modules: Paths_th_env hs-source-dirs: src ghc-options: -Wall -Wcompat build-depends: base <5 , template-haskell , th-compat default-language: Haskell2010 test-suite readme type: exitcode-stdio-1.0 main-is: README.lhs other-modules: Paths_th_env ghc-options: -Wall -Wcompat -pgmL markdown-unlit build-depends: base <5 , markdown-unlit , th-env default-language: Haskell2010