https://github.com/hexresearch/config-app
Creates CLI-apps with config files in yaml format
https://github.com/hexresearch/config-app
Last synced: about 2 months ago
JSON representation
Creates CLI-apps with config files in yaml format
- Host: GitHub
- URL: https://github.com/hexresearch/config-app
- Owner: hexresearch
- License: bsd-3-clause
- Created: 2017-06-27T09:36:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-18T07:50:46.000Z (almost 9 years ago)
- Last Synced: 2025-01-09T03:56:56.747Z (over 1 year ago)
- Language: Haskell
- Size: 8.79 KB
- Stars: 0
- Watchers: 19
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# config-app
Creates CLI-apps with config files in yaml format.
The app has only one field `conf`:
~~~
> app-name --conf config.yaml
~~~
It reads the data from the YAML-file. If the file is missing it tires
to find it at the directory `$(HOME)/.{app-name}/$({APP_NAME}_ENV)/config.yaml`
An example:
~~~haskell
{-# Language
TemplateHaskell
, DeriveDataTypeable
, DeriveGeneric #-}
module Main where
import Data.Data
import GHC.Generics
import System.ConfigApp
data Config = Config {
appFieldA :: !String
, appFieldB :: !Int
} deriving (Show,Eq,Generic,Data)
$(deriveFromJSON defaultOptions ''Config)
main = configApp desc runConfig
where
desc = AppDesc {
appName = "echo-config"
, appDesc = "An app to echo parsed YAML-files"
}
runConfig :: Config -> IO ()
runConfig = print
~~~
To run:
~~~
> echo-config --conf config.yaml
~~~
Config file contains fields with stripped prefix:
~~~yaml
fieldA: 'first'
fieldB: 2
~~~
## Using custom CLI-arguments
The function `configApp` uses only one argument `--conf` if it's not enough
we can use more generic function. To use custom arguments there is a function:
~~~haskell
configAppWith :: (MonadIO m, Data config, FromJSON config)
=> Parser args
-> AppDesc -> (args -> config -> m ()) -> m ()
~~~
It's almost the same as `configApp` but it also takes in an Parser for the rest arguments.
And the callback `runConfig` now takes parsed result as the firt argument.