aedi-property-reader 0.1.0

Aedi property reader, a library for reading configuration properties from multiple sources.


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Aedi property reader, a configuration reader

Dub license Travis CI Code cov Dub version

Aedi property reader is a config reader, with ability to read from xml, json, environment, and command line.

It allows to define a set of default parameters, and extend or override them from environment, command line or any other configuration file.

Features

  • Simple - Get started fast.
  • Powerful - For multi-deployment configurations.
  • Flexible - Supports multiple config formats and sources.
  • Predictable - Well tested foundation for library and app developers.

Installation

Add Aedi property reader as a dependency to a dub project:

Json configuration:

"aedi-property-reader": "~master"

SDL configuration:

dependency "aedi-property-reader" version="~master"

Quickstart

Aedi property reader provides an unified interface for reading config properties out of a multitude of sources. It is able to read configuration out of following sources:

  • Command line
  • Environment
  • Xml document
  • Json document

To use aedi property reader to load configuration following steps are required:

  1. Create a config container
  2. Pass config file, or any required data to it
  3. Define config properties to be read from source
  4. Use properties out of config container

The example below shows the simplest use case presented in steps above:

module app;
import std.stdio;

import aermicioi.aedi;
import aermicioi.aedi_property_reader;

void properties(T : ConvertorContainer!(FromType, ToType), FromType, ToType)(T container) {
		with (container.configure) { // Create a configuration context for config container
			property!string("protocol"); // Define `protocol` property of type `string`
			property!string("host");
			property!string("resource");
			property!ushort("port");
			property!(string[string])("arguments"); // Define `arguments` property of type `string[string]`
			property!(size_t[])("nope-an-array");
		}
}

auto load() {
	auto cont = json("config.json");

	cont.properties();
	return cont;
}

void main()
{
	auto cont = load(); // Initialize config container

	writeln("Dumping network connection information:");
	writeln("Protocol: ", cont.locate!string("protocol")); // Write property found in configuration
	writeln("Host: ", cont.locate!string("host")); 
	writeln("Port: ", cont.locate!ushort("port"));
	writeln("Arguments: ", cont.locate!(string[string])("arguments")); // Write property found in configuration
	writeln("nope-an-array: ", cont.locate!(size_t[])("nope-an-array")); 
}

The output of example, will yield following answers:

Dumping network connection information:
Protocol: http
Host: host.io
Port: 8080
Arguments: ["pass":"json.weak-pass", "user":"json.bold-logic"]
nope-an-array: [6, 5, 4, 3, 2, 1]

Documentation

All public api documentation is available on aermicioi.github.io/aedi-property-reader/.

For a more comprehensive understanding of how library should be used, a set of tutorials are available on github wiki.

Dependencies:
aedi
Versions:
0.1.0 2017-Aug-20
~master 2017-Aug-22
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 1 downloads this month

  • 1 downloads total