Skip to content

Commit

Permalink
Fix Freckle.App.Env for envparse-0.5.2+
Browse files Browse the repository at this point in the history
I think we can do better here, but for now I just did the quickest CPP
to get it compiling.
  • Loading branch information
pbrisbin committed Sep 20, 2024
1 parent 4266ca4 commit 5b40191
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions freckle-env/library/Freckle/App/Env.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

-- | Parse the shell environment for configuration
--
-- A minor extension of [envparse](https://hackage.haskell.org/package/envparse).
Expand Down Expand Up @@ -38,15 +40,21 @@ module Freckle.App.Env
import Prelude

import Control.Error.Util (note)
import Data.Bifunctor (first, second)
import Data.Char (isDigit)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time (UTCTime, defaultTimeLocale, parseTimeM)
import Env hiding (flag)
import Env qualified
import Prelude qualified as Unsafe (read)

#if MIN_VERSION_envparse(0,5,2)
import Data.Bifunctor (second)
import Env hiding (eitherReader, flag)
#else
import Data.Bifunctor (first, second)
import Env hiding (flag)
#endif

-- | Designates the value of a parameter when a flag is not provided.
newtype Off a = Off a

Expand Down Expand Up @@ -83,9 +91,13 @@ flag (Off f) (On t) n m = Env.flag f t n m
--
-- This is a building-block for other 'Reader's
eitherReader :: (String -> Either String a) -> Env.Reader Error a
#if MIN_VERSION_envparse(0,5,2)
eitherReader = Env.eitherReader
#else
eitherReader f s = first (unread . suffix) $ f s
where
suffix x = x <> ": " <> show s
#endif

-- | Read a time value using the given format
--
Expand Down

0 comments on commit 5b40191

Please sign in to comment.