envy-extensible-0.2.0.1: Provides FromEnv in envy instance for Record of extensible.

Copyright(c) 2020 IIJ Innovation Institute Inc.
LicenseBSD3
MaintainerYAMAMOTO Yuji <yuji-yamamoto@iij.ad.jp>
StabilityExperimental
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Envy

Description

Provides functions to create Record from environment variable using Parser.

Synopsis

Documentation

recordFromEnvWithDefault :: forall (xs :: [Assoc Symbol Type]) h. Forall (KeyTargetAre KnownSymbol (Instance1 Var h)) xs => RecordOf h xs -> FieldLabelToEnvName -> Parser (RecordOf h xs) Source #

Parser for Record. This is necessary to implement the instance of FromEnv for Record correctly.

recordFromEnv :: forall (xs :: [Assoc Symbol Type]) h. Forall (KeyTargetAre KnownSymbol (Instance1 Var h)) xs => Parser (RecordOf h xs) Source #

recordFromEnv = recordFromEnvWith $ defaultFieldLabelToEnvName ""

type FieldLabelToEnvName = String -> String Source #

Function to convert field labels of Record into the name of environment variable. Applied to each field label before passing it to env

defaultFieldLabelToEnvName :: String -> FieldLabelToEnvName Source #

The default of FieldLabelToEnvName.

If the first argument is empty, just convert the field label (second argument) into UPPER_SNAKE_CASE.

>>> defaultFieldLabelToEnvName "" "thisIsATest"
"THIS_IS_A_TEST"

Otherwise, convert the field label into UPPER_SNAKE_CASE, then prepend the first argument with an underscore _.

>>> defaultFieldLabelToEnvName "PREFIXED" "thisIsATest"
"PREFIXED_THIS_IS_A_TEST"

camelToUpperSnakeCase :: FieldLabelToEnvName Source #

Used internally in defaultFieldLabelToEnvName. Published for your convenience.