Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- considerEnv :: (Monad m, FromEnv a) => String -> WithEnvT m (Maybe a)
- considerEnvs :: (Monad m, FromEnv a) => [String] -> WithEnvT m (Maybe a)
- withOptions :: (Monad m, FromEnv option) => Maybe option -> [Option ()] -> WithEnvT m (Maybe option)
- withOption :: (Monad m, FromEnv option) => Maybe option -> Option () -> WithEnvT m (Maybe option)
- withOptionDefault :: (Monad m, FromEnv option) => Maybe option -> Option option -> WithEnvT m option
- withOptionSwitch :: Monad m => Bool -> Option Bool -> WithEnvT m Bool
- withOptionSwitch' :: Monad m => a -> (a -> Bool, Bool -> a) -> Option a -> WithEnvT m a
- class FromEnv a where
- type WithEnv = WithEnvT Identity
- newtype WithEnvT m a = WithEnvT {}
- runWithEnv :: [(String, String)] -> WithEnv a -> Either String a
- runWithEnvT :: [(String, String)] -> WithEnvT m a -> m (Either String a)
Documentation
considerEnv :: (Monad m, FromEnv a) => String -> WithEnvT m (Maybe a) Source #
Lookup a key in the application environment then parse the value
with a FromEnv
instance'
considerEnvs :: (Monad m, FromEnv a) => [String] -> WithEnvT m (Maybe a) Source #
Lookup a list of keys with considerEnv
and return the first
value to parse successfully.
withOptions :: (Monad m, FromEnv option) => Maybe option -> [Option ()] -> WithEnvT m (Maybe option) Source #
Lookup a list of keys with withOption
and return the first
value to parse successfully.
withOption :: (Monad m, FromEnv option) => Maybe option -> Option () -> WithEnvT m (Maybe option) Source #
Given the parse result for an option and the Option
record
for that option, query the environment, and then merge the results
from the parser and environment.
withOptionDefault :: (Monad m, FromEnv option) => Maybe option -> Option option -> WithEnvT m option Source #
Given the parse result for an option and the Option
record for
that option, query the environment, and then merge the results from
the parser, environment, and the default.
withOptionSwitch :: Monad m => Bool -> Option Bool -> WithEnvT m Bool Source #
Switches in 'optparse-applicative' have different semantics then
ordinary flags. They are always optional and produce a False
when
absent rather then a Nothing
.
In HGE we give Env Vars a higher precedence then an absent Switch
but the ordinary withEnv
operation expects a Nothing
for an
absent arg parser result.
This function executes with 'withOption Nothing' when the Switch is
absent, otherwise it returns True
.
NOTE: An alternative solution might be to make Switches return
'Maybe _', where '_' is an option specific sum type. This would
allow us to use withOptionDefault
directly. Additionally, all
fields of ServeOptionsRaw
would become Maybe
or First
values
which would allow us to write a 'Monoid ServeOptionsRaw' instance
for combing different option sources.
A Monoid
instance would be super valuable to cleanup arg/env
parsing but this solution feels somewhat unsatisfying.
withOptionSwitch' :: Monad m => a -> (a -> Bool, Bool -> a) -> Option a -> WithEnvT m a Source #
Given an 'Iso a Bool' we can apply the same boolean env merging
semantics as we do for Bool
in withOptionsSwitch
to a
.
class FromEnv a where Source #
A Read
style parser used for consuming Env Vars and building
ReadM
parsers for 'optparse-applicative'.
Instances
The monadic context for querying Env Vars.
Instances
MonadTrans WithEnvT Source # | |
Defined in Hasura.Server.Init.Env | |
MFunctor WithEnvT Source # | |
Monad m => MonadError String (WithEnvT m) Source # | |
Defined in Hasura.Server.Init.Env throwError :: String -> WithEnvT m a # catchError :: WithEnvT m a -> (String -> WithEnvT m a) -> WithEnvT m a # | |
MonadIO m => MonadIO (WithEnvT m) Source # | |
Defined in Hasura.Server.Init.Env | |
Monad m => Applicative (WithEnvT m) Source # | |
Defined in Hasura.Server.Init.Env | |
Functor m => Functor (WithEnvT m) Source # | |
Monad m => Monad (WithEnvT m) Source # | |
Monad m => MonadReader [(String, String)] (WithEnvT m) Source # | |