Reading the configuration file https://code.dlang.org/packages/readconf
Go to file
Alexander Zhirov 504bda31d5 Merge pull request 'support Windows OS' (#4) from dev into master
Reviewed-on: #4
2023-04-29 21:03:08 +00:00
examples v0.3.0-beta.1 2023-03-30 09:58:28 +03:00
img v0.3.0-dev.6 2023-03-28 00:17:46 +03:00
source v0.3.0-dev.8 2023-03-29 19:41:43 +03:00
tests v0.3.0-beta.1 2023-03-30 09:58:28 +03:00
.gitignore v0.1.0 2023-03-24 02:26:02 +03:00
CHANGELOG.md support Windows OS 2023-04-29 23:58:11 +03:00
LICENSE add license 2023-03-23 18:16:40 +03:00
README.md passed all unittests 2023-03-30 10:14:24 +03:00
dub.json support Windows OS 2023-04-29 23:58:11 +03:00
dub.selections.json support Windows OS 2023-04-29 23:58:11 +03:00
dub.settings.json v0.0.1 2023-03-23 18:10:56 +03:00

README.md

readconf

license main githab dub linux

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):

matches.png

Read settings.conf file:

import readconf;
import std.stdio;

void main()
{
    rc.read("./tests/settings.conf");

    foreach (key, param; rc.sn.keys())
        writefln("%s => %s", key, param);

    writeln(rc.sn.key("value1"));

    foreach (key, param; rc.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
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_L4_C1
 ✓ test __unittest_L106_C1
 ✓ test __unittest_L25_C1
 ✓ test __unittest_L51_C1

Summary: 4 passed, 0 failed in 7 ms

DUB

Add a dependency on "readconf": "~>0.3.0"