panfiguration: Merge environment variables and command line options generically

[ apache, library, unclassified ] [ Propose Tags ] [ Report a vulnerability ]

See README.md


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0
Change log CHANGELOG.md
Dependencies barbies, barbies-th (>=0.1.10 && <0.2), base (>=4.10 && <5), bytestring, network, optparse-applicative, split, text [details]
License Apache-2.0
Copyright Copyright (c) 2022 Fumiaki Kinoshita
Author Fumiaki Kinoshita
Maintainer fumiaki.kinoshita@herp.co.jp
Bug tracker https://github.com/herp-inc/panfiguration
Source repo head: git clone https://github.com/herp-inc/panfiguration.git
Uploaded by FumiakiKinoshita at 2022-09-06T12:03:39Z
Distributions
Downloads 128 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-09-06 [all 1 reports]

Readme for panfiguration-0.0

[back to package description]

Usage

Hackage Haskell CI

Panfiguration is a library that provides a composable, automatically-derived interface for configuration parameters.

Currently three backends are supported; envs for environment variables, opts for command-line options and defaults for default values. The Monoid instance makes these backends composable. See the example below for the basic usage.

Example

import Barbies.TH
import Panfiguration

passthroughBareB [d|
    data ServerArgs = ServerArgs
        { http_host :: String
        , http_port :: Int
        , enable_service_log :: Bool
        , environment :: String
        }
    |]

getServerArgs :: IO ServerArgs
getServerArgs = run $ mconcat
    [ logger putStrLn
    , declCase snake
    , envs `withNames` \names -> names
        { http_host = "HTTP_HOST"
        , http_port = "HTTP_PORT"
        }
    , opts `asCase` kebab
    , defaults ServerArgs
        { http_host = Just "0.0.0.0"
        , http_port = Just 8080
        , enable_service_log = Just True
        , environment = Nothing -- required parameter
        }
    ]

Naming conventions

declCase specifies the naming convention of the Haskell data declaration (the default is camel). The naming conventions are configurable by the asCase modifier. By default, envs and opts uses SNAKE_CASE and kebab-case respectively.

The following styles are supported:

AsIs
Camel
camel
snake
SNAKE
kebab
KEBAB
Prefixed <str>

You can also override individual names directly by withNames.