mirage-config 1.0.0

Configuration toolkit supporting JSON, INI and Java Properties


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Mirage Config

Version 1.0.0 Copyright 2022 Mike Bierlee Licensed under the terms of the MIT license - See LICENSE.txt

DUB Package

Toolkit for loading and using application configuration from various formats.

Features:

  • Load from various file formats such as JSON, INI and Java properties (see Formats);
  • Environment variable substitution;
  • Internal configuration substitution (Value in config replaced by other path in config);
  • Parse configuration from string or JSONValue instead of from disk.

Getting started

DUB Dependency

See the DUB project page for instructions on how to include Mirage Config into your project.

Quickstart

import std.stdio : writeln;
import mirage : loadConfig, parseJavaProperties;

void main() {
    // Load configuration from file (see examples/quickstart/config.json)
    auto config = loadConfig("config.json");
    writeln(config.get("application.name"));
    writeln(config.get!long("application.version"));

    // Or parse directly from string
    auto ini = parseIniConfig("
        databaseDriver = Postgres

        [database]
        host = localhost
        port = 5432
    ");

    auto databaseConfig = ini.getConfig("database");

    writeln(ini.get("databaseDriver"));
    writeln(databaseConfig.get("host"));
    writeln(databaseConfig.get("port"));
}

More formats are available (see Formats.) For more details and examples, see the examples directory.

Formats

The following file formats are currently supported:

FormatExtensionImport<sup>*</sup>LoaderParserFactory
any belowany belowmirageloadConfig<sup>**</sup>(N/A)
INI.inimirage.iniloadIniConfigparseIniConfigIniConfigFactory
Java.propertiesmirage.javaloadJavaPropertiesparseJavaPropertiesJavaPropertiesFactory
JSON.jsonmirage.jsonloadJsonConfigparseJsonConfig<sup>***</sup>JsonConfigFactory

<sup>*</sup> Any loader or parser can be imported from the `mirage` package since they are all publicly imported. <sup>**</sup> Loads files based on their extension. If the file does not use one of the extensions in the table, you must use a specific loader. <sup>***</sup> Besides parsing strings like the other formats, it also accepts a `JSONValue`.

Documentation

You can generate documentation from the source code using DUB:

dub build --build=ddox

The documentation can then be found in docs/

History

For a full overview of changes, see CHANGES.md

Contributing

Any and all pull requests are welcome! If you (only) want discuss changes before making them, feel free to open an Issue on github. Please develop your changes on (a branch based on) the develop branch. Continuous integration is preferred so feature branches are not neccessary.

Authors:
  • Mike Bierlee
Dependencies:
none
Versions:
1.0.0 2022-Oct-27
0.0.0 2022-Sep-25
0.0.0-beta.1 2022-Oct-08
~main 2023-Mar-13
~develop 2023-Mar-13
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 285 downloads total

Score:
0.5
Short URL:
mirage-config.dub.pm