2022-09-25 18:43:32 +02:00
# Mirage Config
2022-10-27 19:18:10 +02:00
Version 1.0.0
2023-01-11 00:06:41 +01:00
Copyright 2022-2023 Mike Bierlee
2022-09-25 18:43:32 +02:00
Licensed under the terms of the MIT license - See [LICENSE.txt ](LICENSE.txt )
2022-11-27 19:47:36 +01:00
[![DUB Package ](https://img.shields.io/dub/v/mirage-config.svg )](https://code.dlang.org/packages/mirage-config)
2022-10-09 00:42:55 +02:00
2022-09-25 18:49:15 +02:00
Toolkit for loading and using application configuration from various formats.
2022-09-25 18:43:32 +02:00
2022-09-29 00:31:22 +02:00
Features:
2022-10-08 23:22:34 +02:00
2022-10-13 01:12:27 +02:00
- Load from various file formats such as JSON, INI and Java properties (see [Formats ](#formats ));
2022-09-29 00:31:22 +02:00
- 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.
2022-09-25 18:43:32 +02:00
2022-10-08 23:42:15 +02:00
## Getting started
2022-11-27 19:47:36 +01:00
2022-10-08 23:42:15 +02:00
### DUB Dependency
2022-11-27 19:47:36 +01:00
2022-10-08 23:42:15 +02:00
See the [DUB project page ](https://code.dlang.org/packages/mirage-config ) for instructions on how to include Mirage Config into your project.
### Quickstart
2022-11-27 19:47:36 +01:00
2022-10-08 23:42:15 +02:00
```d
import std.stdio : writeln;
import mirage : loadConfig, parseJavaProperties;
void main() {
2022-10-13 20:37:12 +02:00
// Load configuration from file (see examples/quickstart/config.json)
2022-10-08 23:42:15 +02:00
auto config = loadConfig("config.json");
writeln(config.get("application.name"));
writeln(config.get!long("application.version"));
2022-10-13 20:37:12 +02:00
// Or parse directly from string
auto ini = parseIniConfig("
2022-10-08 23:42:15 +02:00
databaseDriver = Postgres
2022-10-13 20:37:12 +02:00
[database]
host = localhost
port = 5432
2022-10-08 23:42:15 +02:00
");
2022-10-13 20:37:12 +02:00
auto databaseConfig = ini.getConfig("database");
2022-10-08 23:42:15 +02:00
2022-10-13 20:37:12 +02:00
writeln(ini.get("databaseDriver"));
2022-10-08 23:42:15 +02:00
writeln(databaseConfig.get("host"));
writeln(databaseConfig.get("port"));
}
```
2022-10-09 00:46:51 +02:00
More formats are available (see [Formats ](#formats ).)
2022-10-08 23:42:15 +02:00
For more details and examples, see the [examples ](examples ) directory.
## Formats
2022-11-27 19:47:36 +01:00
2022-10-09 00:02:38 +02:00
The following file formats are currently supported:
2022-11-27 19:47:36 +01:00
| Format | Extension | Import< sup > \*</ sup > | Loader | Parser | Factory |
| ----------- | ----------- | ------------------- | --------------------------- | ---------------------------------- | ----------------------- |
| _any below_ | _any below_ | `mirage` | `loadConfig` < sup > \*\*</ sup > | _(N/A)_ | |
| INI | .ini | `mirage.ini` | `loadIniConfig` | `parseIniConfig` | `IniConfigFactory` |
| Java | .properties | `mirage.java` | `loadJavaProperties` | `parseJavaProperties` | `JavaPropertiesFactory` |
| JSON | .json | `mirage.json` | `loadJsonConfig` | `parseJsonConfig` < sup > \*\*\*</ sup > | `JsonConfigFactory` |
2022-10-09 00:02:38 +02:00
< 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`._
2022-10-08 23:42:15 +02:00
2022-11-27 19:47:36 +01:00
## Documentation
2022-10-09 00:06:52 +02:00
You can generate documentation from the source code using DUB:
2022-11-27 19:47:36 +01:00
2022-10-09 00:06:52 +02:00
```
dub build --build=ddox
```
2022-11-27 19:47:36 +01:00
2022-10-09 00:06:52 +02:00
The documentation can then be found in docs/
2022-10-08 23:22:34 +02:00
## History
For a full overview of changes, see [CHANGES.md ](CHANGES.md )
2022-10-09 00:06:52 +02:00
2022-11-27 19:47:36 +01:00
## Poodinis Value Injector
2022-11-28 18:12:55 +01:00
Are you using the [Poodinis Dependency Injection framework ](https://github.com/mbierlee/poodinis )? A value injector is available at [this ](https://github.com/mbierlee/mirage-injector ) repository. See the README on how to use it.
2022-11-27 19:47:36 +01:00
2022-10-09 00:06:52 +02:00
## Contributing
2022-11-27 19:47:36 +01:00
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.