-- 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: -- -- data Error UnsetError :: Error EmptyError :: Error UnreadError :: String -> Error -- | The class of types that contain and can be constructed from the error -- returned from parsing unset variables. class AsUnset e unset :: AsUnset e => e tryUnset :: AsUnset e => e -> Maybe () -- | The class of types that contain and can be constructed from the error -- returned from parsing variables whose value is empty. class AsEmpty e empty :: AsEmpty e => e tryEmpty :: AsEmpty e => e -> Maybe () -- | The class of types that contain and can be constructed from the error -- returned from parsing variable whose value cannot be parsed using the -- Read instance. class AsUnread e unread :: AsUnread e => String -> e tryUnread :: AsUnread e => e -> Maybe String -- | One or none. optional :: Alternative f => f a -> f (Maybe a) -- | Right-to-left Kleisli composition of monads. -- (>=>), with the arguments flipped (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c -- | Left-to-right Kleisli composition of monads. (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c -- | An infix synonym for mappend. (<>) :: Monoid m => m -> m -> m -- | The sum of a collection of actions, generalizing concat. asum :: (Foldable t, Alternative f) => t (f a) -> f a -- | Try to parse a pure environment parsePure :: Parser e b -> [(String, String)] -> Either [(String, e)] b module Env.Generic class Record e a where record = fmap to (gr (State {statePrefix = "", stateCon = "", stateVar = ""})) record :: Record e a => Parser e a class Field e a where field name help = var auto name (foldMap help help) field :: Field e a => String -> Maybe String -> Parser e a -- | Variable tagged with its help message. newtype (?) a tag Help :: a -> (?) a tag [unHelp] :: (?) a tag -> a -- | Representable types of kind *. This class is derivable in GHC with the -- DeriveGeneric flag on. class Generic a instance Data.Traversable.Traversable ((Env.Generic.?) a) instance Data.Foldable.Foldable ((Env.Generic.?) a) instance GHC.Base.Functor ((Env.Generic.?) a) instance forall (k :: BOX) a (tag :: k). GHC.Classes.Eq a => GHC.Classes.Eq (a Env.Generic.? tag) instance forall (k :: BOX) a (tag :: k). GHC.Show.Show a => GHC.Show.Show (a Env.Generic.? tag) instance GHC.Classes.Eq Env.Generic.State instance GHC.Show.Show Env.Generic.State instance Env.Generic.GRecord e a => Env.Generic.GRecord e (GHC.Generics.D1 c a) instance (Env.Error.AsUnset e, Env.Generic.Field e a) => Env.Generic.GRecord e (GHC.Generics.K1 i a) instance (GHC.Generics.Constructor c, Env.Generic.GRecord e a) => Env.Generic.GRecord e (GHC.Generics.C1 c a) instance (Env.Generic.GRecord e f, Env.Generic.GRecord e g) => Env.Generic.GRecord e (f GHC.Generics.:*: g) instance (Env.Generic.GRecord e f, Env.Generic.GRecord e g) => Env.Generic.GRecord e (f GHC.Generics.:+: g) instance (GHC.Generics.Selector c, Env.Generic.Type c ~ 'Env.Generic.Record, Env.Generic.GRecord e a) => Env.Generic.GRecord e (GHC.Generics.S1 c a) instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Types.Int instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Int.Int8 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Int.Int16 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Int.Int32 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Int.Int64 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Integer.Type.Integer instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Types.Word instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Word.Word8 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Word.Word16 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Word.Word32 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Word.Word64 instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Natural.Natural instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Types.Float instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Types.Double instance Env.Error.AsUnset e => Env.Generic.Field e GHC.Base.String instance (Env.Error.AsUnset e, Env.Error.AsUnread e) => Env.Generic.Field e GHC.Types.Char instance (Env.Error.AsUnset e, Env.Error.AsEmpty e) => Env.Generic.Field e GHC.Types.Bool instance (GHC.TypeLits.KnownSymbol tag, Env.Generic.Field e a) => Env.Generic.Field e (a Env.Generic.? tag)