-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parse environment variables -- -- Here's a simple example of a program that uses envparse's -- parser: -- --
-- module Main (main) where
--
-- import Control.Monad (unless)
-- import Env
--
-- data Hello = Hello { name :: String, quiet :: Bool }
--
-- hello :: IO Hello
-- hello = Env.parse (header "envparse example") $
-- Hello <$> var (str <=< nonempty) "NAME" (help "Target for the greeting")
-- <*> switch "QUIET" (help "Whether to actually print the greeting")
--
-- main :: IO ()
-- main = do
-- Hello {name, quiet} <- hello
-- unless quiet $
-- putStrLn ("Hello, " ++ name ++ "!")
--
--
-- The NAME environment variable is mandatory and contains the
-- name of the person to greet. QUIET, on the other hand, is an
-- optional boolean flag, false by default, that decides whether the
-- greeting should be silent.
--
-- If the NAME variable is undefined in the environment then
-- running the program will result in the following help text:
--
-- -- envparse example -- -- Available environment variables: -- -- NAME Target for the greeting -- QUIET Whether to actually print the -- greeting -- -- Parsing errors: -- -- NAME is unset --@package envparse @version 0.3.2 -- | Here's a simple example of a program that uses envparse's -- parser: -- --
-- module Main (main) where
--
-- import Control.Monad (unless)
-- import Env
--
-- data Hello = Hello { name :: String, quiet :: Bool }
--
-- hello :: IO Hello
-- hello = Env.parse (header "envparse example") $
-- Hello <$> var (str <=< nonempty) "NAME" (help "Target for the greeting")
-- <*> switch "QUIET" (help "Whether to actually print the greeting")
--
-- main :: IO ()
-- main = do
-- Hello {name, quiet} <- hello
-- unless quiet $
-- putStrLn ("Hello, " ++ name ++ "!")
--
--
-- The NAME environment variable is mandatory and contains the
-- name of the person to greet. QUIET, on the other hand, is an
-- optional boolean flag, false by default, that decides whether the
-- greeting should be silent.
--
-- If the NAME variable is undefined in the environment then
-- running the program will result in the following help text:
--
-- -- envparse example -- -- Available environment variables: -- -- NAME Target for the greeting -- QUIET Whether to actually print the -- greeting -- -- Parsing errors: -- -- NAME is unset --module Env -- | Parse the environment or die -- -- Prints the help text and exits with EXIT_FAILURE on -- encountering a parse error. -- --
-- >>> parse (header "env-parse 0.2.0") (var str "USER" (def "nobody")) --parse :: (Info Error -> Info e) -> Parser e a -> IO a -- | Try to parse the environment -- -- Use this if simply dying on failure (the behavior of parse) is -- inadequate for your needs. parseOr :: (String -> IO a) -> (Info Error -> Info e) -> Parser e b -> IO (Either a b) -- | An environment parser data Parser e a -- | This represents a modification of the properties of a particular -- Parser. Combine them using the Monoid instance. data Mod t a -- | Parser's metadata data Info e -- | Set the help text header (it usually includes the application's name -- and version) header :: String -> Info e -> Info e -- | Set the short description desc :: String -> Info e -> Info e -- | Set the help text footer (it usually includes examples) footer :: String -> Info e -> Info e -- | An error handler handleError :: ErrorHandler e -> Info x -> Info e -- | Given a variable name and an error value, try to produce a useful -- error message type ErrorHandler e = String -> e -> Maybe String -- | The default error handler defaultErrorHandler :: (AsUnset e, AsEmpty e, AsUnread e) => ErrorHandler e -- | The string to prepend to the name of every declared environment -- variable prefixed :: String -> Parser e a -> Parser e a -- | Parse a particular variable from the environment -- --
-- >>> var str "EDITOR" (def "vim" <> helpDef show) --var :: AsUnset e => Reader e a -> String -> Mod Var a -> Parser e a -- | Environment variable metadata data Var a -- | An environment variable's value parser. Use (<=<) and -- (>=>) to combine these type Reader e a = String -> Either e a -- | The trivial reader str :: IsString s => Reader e s -- | The reader that accepts only non-empty strings nonempty :: (AsEmpty e, IsString s) => Reader e s -- | The reader that uses the Read instance of the type auto :: (AsUnread e, Read a) => Reader e a -- | The default value of the variable -- -- Note: specifying it means the parser won't ever fail. def :: a -> Mod Var a -- | Show the default value of the variable in help. helpDef :: (a -> String) -> Mod Var a -- | A flag that takes the active value if the environment variable is set -- and non-empty and the default value otherwise -- -- Note: this parser never fails. flag :: (AsUnset e, AsEmpty e) => a -> a -> String -> Mod Flag a -> Parser e a -- | A simple boolean flag -- -- Note: the same caveats apply. switch :: (AsUnset e, AsEmpty e) => String -> Mod Flag Bool -> Parser e Bool -- | Flag metadata data Flag a -- | A class of things that can have a help message attached to them class HasHelp t -- | Attach help text to the variable help :: HasHelp t => String -> Mod t a -- | A pretty-printed list of recognized environment variables suitable for -- usage messages helpDoc :: Parser e a -> String -- | The type of errors returned by envparse's Readers. -- These fall into 3 categories: -- --