legion-extra-0.1.0.3: Extra non-essential utilities for building legion applications.

Safe HaskellNone
LanguageHaskell2010

Network.Legion.Config

Description

This module contains a common pattern for parsing the legion runtime settings and application-specific configuration from the command line. The intent of this module is to implement a very specific and simple pattern that some people find useful and to get them there with minimum effort; not to be a flexible solution to every problem in the domain of configuration, or even to endorse the use of this pattern if you think you might need something different.

This parseArgs function implements a command line parser that accepts the usage:

<your-program-name>
 -c <file>         --config=<file>             REQUIRED - Specifies the config file.
 -j <host>:<port>  --joinTarget=<host>:<port>  OPTIONAL - The address of a node in the cluster we want to join.

The config file is a YAML file, which has the following format:

adminAddr: localhost:8080
peerAddr: localhost:8022
joinAddr: localhost:8023

In addition to these bindings, an arbitrary set of additional bindings may be supplied, and which will be decoded into some FromJSON instance type of your choosing. (Note that the yaml package is implemented by transforming the YAML input to JSON and then delegating to aeson, which is why your custom config type must be FromJSON, even though the config file is YAML format.)

After parsing the command line and config file, parseArgs will then return a tuple containing the legionary runtime settings, the startup mode that should be used, and custom application configuration.

Synopsis

Documentation

parseArgs :: FromJSON userConfig => IO (RuntimeSettings, StartupMode, userConfig) Source #

Parse the command line arguments.