-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Conditionally running IO actions based on environment variables. -- -- This package provides functions for validating presence / contents of -- environment variables, and conditionally running IO actions based on -- the result. @package env-guard @version 0.2 -- | System.Environment.Guard for MonadIO. module System.Environment.Guard.Lifted -- | The expectation for an environment variable lookup. data ExpectEnv -- | Expect that the environment variable is set (i.e. contents can be -- anything). ExpectEnvSet :: ExpectEnv -- | Expect that the environment variable is set and the contents equals -- the string. This is case-insensitive. ExpectEnvEquals :: String -> ExpectEnv -- | Expect that the environment variable is set and its contents satisfies -- the predicate. ExpectEnvPredicate :: (String -> Bool) -> ExpectEnv -- | Guards an action behind an environment variable according to the given -- expectation. -- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> withGuard "FOO" (ExpectEnvEquals "baz") (putStrLn "succeeded")
--   Nothing
--   
-- --
--   >>> withGuard "FOO" ExpectEnvSet (putStrLn "succeeded")
--   succeeded
--   Just ()
--   
withGuard :: MonadIO m => String -> ExpectEnv -> m a -> m (Maybe a) -- | Variant of withGuard that ignores the return value. withGuard_ :: MonadIO m => String -> ExpectEnv -> m a -> m () -- | guardOrElse var expect m1 m2 is equivalent to withGuard -- var expect m1 except that it runs m2 if m1 is -- not run. -- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> guardOrElse "FOO" ExpectEnvSet (pure True) (pure "not found")
--   Right True
--   
-- --
--   >>> guardOrElse "BAR" ExpectEnvSet (pure True) (pure "not found")
--   Left "not found"
--   
guardOrElse :: MonadIO m => String -> ExpectEnv -> m a -> m e -> m (Either e a) -- | guardOrElse specialized to the same type so that we always -- return an a. This can also be used to ignore the return value -- i.e. -- --
--   guardOrElse' var expect (void m1) m2
--   
-- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> guardOrElse' "FOO" ExpectEnvSet (pure True) (pure False)
--   True
--   
-- --
--   >>> guardOrElse' "BAR" ExpectEnvSet (pure True) (pure False)
--   False
--   
-- --
--   >>> guardOrElse' "BAR" ExpectEnvSet (void $ pure True) (putStrLn "not found")
--   not found
--   
guardOrElse' :: MonadIO m => String -> ExpectEnv -> m a -> m a -> m a -- | guardSet var io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
-- --
--   guardSet var === guardPredicate var (const True)
--   
-- --

Examples

-- --
--   >>> guardSet "NOT_SET" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "SET" "foo"
--   
--   >>> guardSet "SET" (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardSet :: MonadIO m => String -> m a -> m (Maybe a) -- | Variant of guardSet that ignores the return value. guardSet_ :: MonadIO m => String -> m a -> m () -- | guardEquals var expected io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
  3. var's value equals expected. This is -- case-insensitive.
  4. --
-- --
--   guardEquals var expected === guardPredicate var (\a b -> fmap toLower a == fmap toLower b)
--   
-- --

Examples

-- --
--   >>> guardEquals "NOT_SET" "val" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WRONG_VAL" "good_val"
--   
--   >>> guardEquals "WRONG_VAL" "bad_val" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WILL_RUN" "val"
--   
--   >>> guardEquals "WILL_RUN" "VAL" (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardEquals :: MonadIO m => String -> String -> m a -> m (Maybe a) -- | Variant of guardEquals_ that ignores the return value. guardEquals_ :: MonadIO m => String -> String -> m a -> m () -- | This is the most general way to check an environment variable. -- guardPredicate var p io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
  3. var's value satisfies predicate p.
  4. --
-- --

Examples

-- --
--   >>> guardPredicate "NOT_SET" (const True) (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "CASE_WRONG" "VAL"
--   
--   >>> guardPredicate "CASE_WRONG" (== "val") (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WILL_RUN" "VAL"
--   
--   >>> guardPredicate "WILL_RUN" (== "VAL") (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardPredicate :: MonadIO m => String -> (String -> Bool) -> m a -> m (Maybe a) -- | Variant of guardPredicate that ignores the return value. guardPredicate_ :: MonadIO m => String -> (String -> Bool) -> m a -> m () instance GHC.Show.Show System.Environment.Guard.Lifted.ExpectEnv -- | Functions for conditionally running IO actions based on an -- environment variable. module System.Environment.Guard -- | The expectation for an environment variable lookup. data ExpectEnv -- | Expect that the environment variable is set (i.e. contents can be -- anything). ExpectEnvSet :: ExpectEnv -- | Expect that the environment variable is set and the contents equals -- the string. This is case-insensitive. ExpectEnvEquals :: String -> ExpectEnv -- | Expect that the environment variable is set and its contents satisfies -- the predicate. ExpectEnvPredicate :: (String -> Bool) -> ExpectEnv -- | Guards an action behind an environment variable according to the given -- expectation. -- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> withGuard "FOO" (ExpectEnvEquals "baz") (putStrLn "succeeded")
--   Nothing
--   
-- --
--   >>> withGuard "FOO" ExpectEnvSet (putStrLn "succeeded")
--   succeeded
--   Just ()
--   
withGuard :: String -> ExpectEnv -> IO a -> IO (Maybe a) -- | Variant of withGuard that ignores the return value. withGuard_ :: String -> ExpectEnv -> IO a -> IO () -- | guardOrElse var expect io1 io2 is equivalent to withGuard -- var expect io1 except that it runs io2 if io1 -- is not run. -- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> guardOrElse "FOO" ExpectEnvSet (pure True) (pure "not found")
--   Right True
--   
-- --
--   >>> guardOrElse "BAR" ExpectEnvSet (pure True) (pure "not found")
--   Left "not found"
--   
guardOrElse :: String -> ExpectEnv -> IO a -> IO e -> IO (Either e a) -- | guardOrElse specialized to the same type so that we always -- return an a. This can also be used to ignore the return value -- i.e. -- --
--   guardOrElse' var expect (void io1) io2
--   
-- --

Examples

-- --
--   >>> setEnv "FOO" "bar"
--   
--   >>> guardOrElse' "FOO" ExpectEnvSet (pure True) (pure False)
--   True
--   
-- --
--   >>> guardOrElse' "BAR" ExpectEnvSet (pure True) (pure False)
--   False
--   
-- --
--   >>> guardOrElse' "BAR" ExpectEnvSet (void $ pure True) (putStrLn "not found")
--   not found
--   
guardOrElse' :: String -> ExpectEnv -> IO a -> IO a -> IO a -- | guardSet var io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
-- --
--   guardSet var === guardPredicate var (const True)
--   
-- --

Examples

-- --
--   >>> guardSet "NOT_SET" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "SET" "foo"
--   
--   >>> guardSet "SET" (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardSet :: String -> IO a -> IO (Maybe a) -- | Variant of guardSet that ignores the return value. guardSet_ :: String -> IO a -> IO () -- | guardEquals var expected io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
  3. var's value equals expected. This is -- case-insensitive.
  4. --
-- --
--   guardEquals var expected === guardPredicate var (\a b -> fmap toLower a == fmap toLower b)
--   
-- --

Examples

-- --
--   >>> guardEquals "NOT_SET" "val" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WRONG_VAL" "good_val"
--   
--   >>> guardEquals "WRONG_VAL" "bad_val" (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WILL_RUN" "val"
--   
--   >>> guardEquals "WILL_RUN" "VAL" (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardEquals :: String -> String -> IO a -> IO (Maybe a) -- | Variant of guardEquals_ that ignores the return value. guardEquals_ :: String -> String -> IO a -> IO () -- | This is the most general way to check an environment variable. -- guardPredicate var p io runs io iff -- --
    --
  1. The environment variable var is set.
  2. --
  3. var's value satisfies predicate p.
  4. --
-- --

Examples

-- --
--   >>> guardPredicate "NOT_SET" (const True) (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "CASE_WRONG" "VAL"
--   
--   >>> guardPredicate "CASE_WRONG" (== "val") (putStrLn "ran io" $> True)
--   Nothing
--   
-- --
--   >>> setEnv "WILL_RUN" "VAL"
--   
--   >>> guardPredicate "WILL_RUN" (== "VAL") (putStrLn "ran io" $> True)
--   ran io
--   Just True
--   
guardPredicate :: String -> (String -> Bool) -> IO a -> IO (Maybe a) -- | Variant of guardPredicate that ignores the return value. guardPredicate_ :: String -> (String -> Bool) -> IO a -> IO ()