| Copyright | (c) Justin Le 2016 |
|---|---|
| License | BSD3 |
| Maintainer | justin@jle.im |
| Stability | unstable |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Configurator.Export
Contents
Description
Pretty printers and exporters for Configs from the configurator
library, in Data.Configurator.
All results are intended to be valid parsing files in the configuration file syntax of the library.
For a full round trip:
main = do cfg <- load [Required "config.cfg"] writeConf "config.cfg" cfg
This should load the config file, parse it, and then re-export it, rewriting the original config file. The result should be an identical configuration file (with keys potentially re-arranged and re-sorted, comments removed, etc.)
Print/export your own dynmically generated configuration files by
manipulating the that a HashMap Name ValueConfig gives with
getMap.
Sample output:
foo {
bar {
baz1 = true
baz2 = [1, 0.6, "hello", true]
}
aardvark = "banana"
monkey = [true, false, 1.9e-3]
zebra = 24
}
foo2 {
bar = 8.1e-8
}
apple = ["cake", true]
orange = 8943Further configuration on sorting of keys, displaying of bools and
floats, etc. is possible by passing in custom ConfStyle values.
- renderConf :: Config -> IO String
- displayConf :: Config -> IO ()
- writeConf :: FilePath -> Config -> IO ()
- renderHashMap :: HashMap Name Value -> String
- confDoc :: Config -> IO Doc
- hashMapDoc :: HashMap Name Value -> Doc
- confStyle :: ConfStyle
- data ConfStyle = ConfStyle {}
- data AlignStyle
- data BraceStyle
- data BoolStyle
- data KeyType
- renderConf' :: ConfStyle -> Config -> IO String
- displayConf' :: ConfStyle -> Config -> IO ()
- writeConf' :: ConfStyle -> FilePath -> Config -> IO ()
- renderHashMap' :: ConfStyle -> HashMap Name Value -> String
- confDoc' :: ConfStyle -> Config -> IO Doc
- hashMapDoc' :: ConfStyle -> HashMap Name Value -> Doc
Default styles
Pretty printing / Exporting
renderConf :: Config -> IO String Source
displayConf :: Config -> IO () Source
Print out a pretty printed rendering of the current contents of the
Config to stdout.
Doc
With styles
Describing styles
Sensible defaults for a ConfStyle:
confStyle ::ConfStyleconfStyle =ConfStyle{ confStyleIndent = 4 , confStyleAlign =AlignOn2 , confStyleBraceStyle =SameLineBrace, confStyleBoolStyle =TrueFalse, confStyleForceDec = False , confStyleShowInts = True -- sort by "type" of key, then sort alphabetically , confStyleSortBy =comparingsnd<>comparing fst , confStyleGroupSep = 0 , confStyleValueSep = 0 , confStyleTopSep = 1 }
It's recommended that you create ConfStyles by modifying this value
using record syntax rather than create your own from scratch:
myStyle =confStyle{ confStyleBraceStyle =NewLineBrace, confStyleBoolStyle =OnOff}
Style options for pretty-printing the contents of a Config.
Sensible defaults are given as confStyle; it's recommended that you
start with confStyle as a default and use record syntax to modify it
to what you want. See confStyle for more details.
Constructors
| ConfStyle | |
Fields
| |
data AlignStyle Source
Alignment style of equals signs on contiguous sets of keys of values.
Constructors
| NoAlign | Don't align equals signs at all. |
| AlignAny | Align them to the longest key. |
| AlignOn Int | Align to the longest key, but make sure the identation is a multiple of this number. |
Instances
data BraceStyle Source
Placement style of opening braces (curly brackets) for groups.
Constructors
| SameLineBrace | Opening braces go on the same line as the key name. |
| NewLineBrace | Opening braces go on a new line after the key name. |
Instances
The style of boolean literals display Bools as. Both are accepted
by configurator's parser.
The type of structure that the key contains. Used for sorting.
Pretty printing / Exporting
displayConf' :: ConfStyle -> Config -> IO () Source
Doc
hashMapDoc' :: ConfStyle -> HashMap Name Value -> Doc Source
Convert a HashMap of keys and Values into a Doc, from the
pretty package. This allows more fine-grained control over printing
it. Takes a ConfStyle with the rendering style.
Expects keys to be in the format exported from a Config using
getMap. "foo.bar.baz.x" is "x" in group "baz" in group "bar" in group
"foo", etc.