-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Tools for specifying and parsing configurations -- -- Tools for specifying and parsing configurations -- -- This package provides a collection of utils on top of the packages -- optparse-applicative, aeson, and yaml for -- configuring libraries and applications in a convenient and composable -- way. -- -- The main features are -- --
-- module Main (main) where -- -- import Configuration.Utils.Setup ---- -- With both methods the field Build-Type in the package -- description (cabal) file must be set to Custom: -- --
-- Build-Type: Custom ---- -- = Integration With Configuration.Utils -- -- You can integrate the information provided by the PkgInfo -- modules with the command line interface of an application by importing -- the respective module for the component and using the -- runWithPkgInfoConfiguration function from the module -- Configuration.Utils as show in the following example: -- --
-- {-# LANGUAGE OverloadedStrings #-}
-- {-# LANGUAGE FlexibleInstances #-}
--
-- module Main
-- ( main
-- ) where
--
-- import Configuration.Utils
-- import PkgInfo
--
-- instance FromJSON (() -> ()) where parseJSON _ = pure id
--
-- mainInfo :: ProgramInfo ()
-- mainInfo = programInfo "Hello World" (pure id) ()
--
-- main :: IO ()
-- main = runWithPkgInfoConfiguration mainInfo pkgInfo . const $ putStrLn "hello world"
--
--
-- With that the resulting application supports the following additional
-- command line options:
--
-- -- (info message, detailed info message, version string, license text) ---- -- See the documentation of Configuration.Utils.Setup for a way -- how to generate this information automatically from the package -- description during the build process. type PkgInfo = (String, String, String, String) -- | Run an IO action with a configuration that is obtained by updating the -- given default configuration the values defined via command line -- arguments. -- -- In addition to the options defined by the given options parser the -- following options are recognized: -- --
-- data Auth = Auth
-- { _user ∷ !String
-- , _pwd ∷ !String
-- }
--
-- user ∷ Functor φ ⇒ (String → φ String) → Auth → φ Au user f s = (\u → s { _user = u }) <$> f (_user s)
-- pwd ∷ Functor φ ⇒ (String → φ String) → Auth → φ Au pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s)
-- -- or with lenses and TemplateHaskell just:
-- -- $(makeLenses ''Auth)
--
-- pAuth ∷ MParser Auth
-- pAuth = id
-- <$< user .:: strOption
-- × long "user"
-- ⊕ short 'u' ⊕ help "user name" <*< pwd .:: strOption
-- × long "pwd"
-- ⊕ help "password for user"
--
(.::) :: (Alternative φ, Applicative φ) => Lens' α β -> φ β -> φ (α -> α)
-- | An operator for applying a setter to an option parser that yields a
-- modification function.
--
-- Example usage:
--
--
-- data HttpURL = HttpURL
-- { _auth ∷ !Auth
-- , _domain ∷ !String
-- }
--
-- auth ∷ Functor φ ⇒ (Auth → φ Auth) → HttpURL → φ HttpU auth f s = (\u → s { _auth = u }) <$> f (_auth s)
-- domain ∷ Functor φ ⇒ (String → φ String) → HttpURL → φ HttpU domain f s = (\u → s { _domain = u }) <$> f (_domain s)
-- path ∷ Functor φ ⇒ (String → φ String) → HttpURL → φ HttpU path f s = (\u → s { _path = u }) <$> f (_path s)
-- -- or with lenses and TemplateHaskell just:
-- -- $(makeLenses ''HttpURL)
--
-- pHttpURL ∷ MParser HttpURL
-- pHttpURL = id
-- <$< auth %:: pAuth
-- <*< domain .:: strOption
-- × long "domain"
-- ⊕ short 'd' ⊕ help "HTTP domain"
--
(%::) :: (Alternative φ, Applicative φ) => Lens' α β -> φ (β -> β) -> φ (α -> α)
-- | A JSON Value parser for a property of a given Object
-- that updates a setter with the parsed value.
--
--
-- data Auth = Auth
-- { _userId ∷ !Int
-- , _pwd ∷ !String
-- }
--
-- userId ∷ Functor φ ⇒ (Int → φ Int) → Auth → φ Au userId f s = (\u → s { _userId = u }) <$> f (_userId s)
-- pwd ∷ Functor φ ⇒ (String → φ String) → Auth → φ Au pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s)
-- -- or with lenses and TemplateHaskell just:
-- -- $(makeLenses ''Auth)
--
-- instance FromJSON (Auth → Auth) where parseJSON = withObject "Auth" $ \o → id <$< setProperty user "user" p o
-- <*< setProperty pwd "pwd" parseJSON o
-- where
-- p = withText "user" $ \case
-- "alice" → pure (0 ∷ Int) "bob" → pure 1 e → faile $ "unrecognized user " ⊕
--
setProperty :: Lens' α β -> Text -> (Value -> Parser β) -> Object -> Parser (α -> α)
-- | A variant of the setProperty that uses the default
-- parseJSON method from the FromJSON instance to parse the
-- value of the property. Its usage pattern mimics the usage pattern of
-- the .: operator from the aeson library.
--
--
-- data Auth = Auth
-- { _user ∷ !String
-- , _pwd ∷ !String
-- }
--
-- user ∷ Functor φ ⇒ (String → φ String) → Auth → φ Au user f s = (\u → s { _user = u }) <$> f (_user s)
-- pwd ∷ Functor φ ⇒ (String → φ String) → Auth → φ Au pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s)
-- -- or with lenses and TemplateHaskell just:
-- -- $(makeLenses ''Auth)
--
-- instance FromJSON (Auth → Auth) where parseJSON = withObject "Auth" $ \o → id <$< user ..: "user" × o
-- <*< pwd ..: "pwd" × o
--
(..:) :: FromJSON β => Lens' α β -> Text -> Object -> Parser (α -> α)
-- | A variant of the aeson operator .: that creates a parser that
-- modifies a setter with a parsed function.
--
--
-- data HttpURL = HttpURL
-- { _auth ∷ !Auth
-- , _domain ∷ !String
-- }
--
-- auth ∷ Functor φ ⇒ (Auth → φ Auth) → HttpURL → φ HttpU auth f s = (\u → s { _auth = u }) <$> f (_auth s)
-- domain ∷ Functor φ ⇒ (String → φ String) → HttpURL → φ HttpU domain f s = (\u → s { _domain = u }) <$> f (_domain s)
-- path ∷ Functor φ ⇒ (String → φ String) → HttpURL → φ HttpU path f s = (\u → s { _path = u }) <$> f (_path s)
-- -- or with lenses and TemplateHaskell just:
-- -- $(makeLenses ''HttpURL)
--
-- instance FromJSON (HttpURL → HttpURL) where parseJSON = withObject "HttpURL" $ \o → id <$< auth %.: "auth" × o
-- <*< domain ..: "domain" × o
--
(%.:) :: FromJSON (β -> β) => Lens' α β -> Text -> Object -> Parser (α -> α)
-- | This operator is an alternative for $ with a higher precedence
-- which makes it suitable for usage within Applicative style funtors
-- without the need to add parenthesis.
(%) :: (α -> β) -> α -> β
-- | This operator is a UTF-8 version of % which is an alternative
-- for $ with a higher precedence which makes it suitable for
-- usage within Applicative style funtors without the need to add
-- parenthesis.
--
-- The hex value of the UTF-8 character × is 0x00d7.
--
-- In VIM type: Ctrl-V u 00d7
--
-- You may also define a key binding by adding something like the
-- following line to your vim configuration file:
--
-- -- iabbrev <buffer> >< × --(×) :: (α -> β) -> α -> β -- | Functional composition for applicative functors. (<*<) :: Applicative φ => φ (β -> γ) -> φ (α -> β) -> φ (α -> γ) -- | Functional composition for applicative functors with its arguments -- flipped. (>*>) :: Applicative φ => φ (α -> β) -> φ (β -> γ) -> φ (α -> γ) -- | Applicative functional composition between a pure function and an -- applicative function. (<$<) :: Functor φ => (β -> γ) -> φ (α -> β) -> φ (α -> γ) -- | Applicative functional composition between a pure function and an -- applicative function with its arguments flipped. (>$>) :: Functor φ => φ (α -> β) -> (β -> γ) -> φ (α -> γ) -- | Functional composition for applicative functors. -- -- This is a rather popular operator. Due to conflicts (for instance with -- the lens package) it may have to be imported qualified. -- | Deprecated: use <*< instead (<.>) :: Applicative φ => φ (β -> γ) -> φ (α -> β) -> φ (α -> γ) -- | For people who like nicely aligned code and do not mind messing with -- editor key-maps: here a version of <.> that uses a -- unicode symbol -- -- The hex value of the UTF-8 character ⊙ is 0x2299. -- -- A convenient VIM key-map is: -- --
-- iabbrev <buffer> ../ ⊙ ---- | Deprecated: use <*< instead (⊙) :: Applicative φ => φ (β -> γ) -> φ (α -> β) -> φ (α -> γ) dropAndUncaml :: Int -> String -> String -- | This is the same type as the type from the lens library with the same -- name. type Lens' σ α = Lens σ σ α α -- | This is the same type as the type from the lens library with the same -- name. type Lens σ τ α β = Functor φ => (α -> φ β) -> σ -> φ τ instance (FromJSON (a -> a), FromJSON a) => FromJSON (Maybe a -> Maybe a) module Configuration.Utils.Http -- | In order to make TLS optional this type should be used wrapped into a -- Maybe. data HttpServiceTLSConfiguration hstcCertFile :: Lens' HttpServiceTLSConfiguration FilePath hstcKeyFile :: Lens' HttpServiceTLSConfiguration FilePath -- | We restrict services to use either HTTP or HTTPS but not both. -- -- TLS can be turned off explicitely in the configuration file by setting -- the respective section to null. It can not be turned on or -- off via command line options. But once it is turned on the values for -- the certificate and key file can be changed by command line options. data HttpServiceConfiguration hscHost :: Lens' HttpServiceConfiguration ByteString hscPort :: Lens' HttpServiceConfiguration Int hscUseTLS :: Lens' HttpServiceConfiguration (Maybe HttpServiceTLSConfiguration) defaultHttpServiceConfiguration :: HttpServiceConfiguration pHttpServiceConfiguration :: String -> MParser HttpServiceConfiguration data HttpClientConfiguration hccHost :: Lens' HttpClientConfiguration ByteString hccPort :: Lens' HttpClientConfiguration Int hccUseTLS :: Lens' HttpClientConfiguration Bool defaultHttpClientConfiguration :: HttpClientConfiguration pHttpClientConfiguration :: String -> MParser HttpClientConfiguration httpService2clientConfiguration :: HttpServiceConfiguration -> HttpClientConfiguration instance Show HttpServiceTLSConfiguration instance Read HttpServiceTLSConfiguration instance Eq HttpServiceTLSConfiguration instance Ord HttpServiceTLSConfiguration instance Show HttpServiceConfiguration instance Read HttpServiceConfiguration instance Eq HttpServiceConfiguration instance Ord HttpServiceConfiguration instance Show HttpClientConfiguration instance Read HttpClientConfiguration instance Eq HttpClientConfiguration instance Ord HttpClientConfiguration instance ToJSON HttpClientConfiguration instance FromJSON (HttpClientConfiguration -> HttpClientConfiguration) instance ToJSON HttpServiceConfiguration instance FromJSON (HttpServiceConfiguration -> HttpServiceConfiguration) instance ToJSON HttpServiceTLSConfiguration instance FromJSON HttpServiceTLSConfiguration instance FromJSON (HttpServiceTLSConfiguration -> HttpServiceTLSConfiguration)