Reading the configuration file
https://code.dlang.org/packages/readconf
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
### New - Reading empty parameter values - Parameter name as a single character ### Bug fixes - Generating an exception when accessing a non-existent section |
4 weeks ago | |
---|---|---|
examples | 4 weeks ago | |
img | 4 weeks ago | |
source | 4 weeks ago | |
tests | 4 weeks ago | |
.gitignore | 4 months ago | |
CHANGELOG.md | 4 weeks ago | |
LICENSE | 4 months ago | |
README.md | 4 weeks ago | |
dub.json | 4 weeks ago | |
dub.selections.json | 4 weeks ago | |
dub.settings.json | 4 months ago |
README.md
Singleton for reading the configuration file required for your program.
What can do
- Reading multiple configuration files
- Separation of parameters by sections
- Access to parameters and sections using keys and indexes
- Commenting on lines
You will get more detailed information on the wiki.
Quick start
The settings.conf
file (see the tests):
Read settings.conf
file:
import readconf;
import std.stdio;
void main()
{
rc.read("./tests/settings.conf");
foreach (key, param; rc.cf.sn.keys())
writefln("%s => %s", key, param);
writeln(rc.cf.sn.key("value1"));
foreach (key, param; rc.cf.sn("part2").keys())
writefln("%s => %s", key, param);
writeln(rc[]["part2"]["value1"]);
}
Result:
value1 => text without quotes
value2 => Yes!
value3 => value in apostrophes
value4 => 1000
value5 => 0.000
value6 =>
value7 => //path
value8 => "Hey!"
text without quotes
value1 => this value will be in the new section
value3 => good value!
this value will be in the new section
Unittests
The unittests provide examples of configuration files and the settings.conf
file located in the tests:
Running bin/readconf-test-unittest
✓ test __unittest_L111_C1
✓ test __unittest_L26_C1
✓ test __unittest_L52_C1
✓ test __unittest_L4_C1
Summary: 4 passed, 0 failed in 7 ms
DUB
Add a dependency on "readconf": "~>0.4.0"