Skip to content

aermicioi/aedi-property-reader

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
November 26, 2018 13:08
June 16, 2017 23:33
June 21, 2018 23:13

Aedi property reader, a configuration reader

Dub license Travis CI Code cov Dub version

Aedi property reader is a library for loading config properties from various sources, like xml, json, yaml, or sdlang.

Features

  • Simple - Init container, define properties, use it.
  • Powerful - Hierarchical organization of multiple files.
  • Flexible - Supports multiple config formats and sources.
  • Smart - Uses document syntax to guess D types for properties.

Installation

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

Json configuration:

"aedi-property-reader": "~>0.2.0"

SDL configuration:

dependency "aedi-property-reader" version="~>0.2.0"

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
  • json
  • sdlang
  • yaml
  • java like property files

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

  1. Create a property container out of a string or a file in specified format
  2. Define config properties to be read from source
  3. Use properties from 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
		register!string("protocol"); // Define `protocol` property of type `string`
		register!string("host");
		register!string("resource");
		register!ushort("port");
		register!(string[string])("arguments"); // Define `arguments` property of type `string[string]`
		register!(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/.

About

Aedi extension, that loads data from multiple sources (environment, xml, json, etc.)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages