readconf/README.md

83 lines
2.5 KiB
Markdown
Raw Normal View History

2023-04-29 21:21:06 +00:00
![readconf](img/readconf.png)
2023-03-23 15:10:56 +00:00
[![license](https://img.shields.io/github/license/AlexanderZhirov/readconf.svg?sort=semver&style=for-the-badge&color=green)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
2023-03-29 16:41:43 +00:00
[![main](https://img.shields.io/badge/dynamic/json.svg?label=git.zhirov.kz&style=for-the-badge&url=https://git.zhirov.kz/api/v1/repos/dlang/readconf/tags&query=$[0].name&color=violet&logo=D)](https://git.zhirov.kz/dlang/readconf)
[![githab](https://img.shields.io/github/v/tag/AlexanderZhirov/readconf.svg?sort=semver&style=for-the-badge&color=blue&label=github&logo=D)](https://github.com/AlexanderZhirov/readconf)
[![dub](https://img.shields.io/dub/v/readconf.svg?sort=semver&style=for-the-badge&color=orange&logo=D)](https://code.dlang.org/packages/readconf)
[![linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)](https://www.linux.org/)
2023-04-29 21:07:44 +00:00
[![windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)](https://support.microsoft.com/en-US/windows)
2023-03-23 15:10:56 +00:00
Singleton for reading the configuration file required for your program.
2023-03-26 01:00:06 +00:00
## What can do
2023-03-30 06:58:28 +00:00
- 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](https://git.zhirov.kz/dlang/readconf/wiki).
2023-03-26 01:00:06 +00:00
2023-03-23 23:26:02 +00:00
## Quick start
2023-03-23 15:10:56 +00:00
2023-03-23 23:26:02 +00:00
The `settings.conf` file (see the [tests](tests/)):
![matches.png](img/matches.png)
2023-03-23 15:10:56 +00:00
2023-03-30 07:14:24 +00:00
Read `settings.conf` file:
2023-03-23 15:10:56 +00:00
```d
import readconf;
import std.stdio;
void main()
{
2023-03-30 06:58:28 +00:00
rc.read("./tests/settings.conf");
2023-03-23 15:10:56 +00:00
foreach (key, param; rc.cf.sn.keys())
2023-03-23 15:10:56 +00:00
writefln("%s => %s", key, param);
writeln(rc.cf.sn.key("value1"));
2023-03-26 00:26:31 +00:00
foreach (key, param; rc.cf.sn("part2").keys())
2023-03-26 00:26:31 +00:00
writefln("%s => %s", key, param);
writeln(rc[]["part2"]["value1"]);
2023-03-23 15:10:56 +00:00
}
```
Result:
```
2023-03-26 00:26:31 +00:00
value1 => text without quotes
value2 => Yes!
value3 => value in apostrophes
value4 => 1000
value5 => 0.000
value6 =>
2023-03-26 00:26:31 +00:00
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
2023-03-23 15:10:56 +00:00
```
2023-03-26 01:00:06 +00:00
2023-03-30 07:14:24 +00:00
## Unittests
The unittests provide [examples](examples/) of configuration files and the `settings.conf` file located in the [tests](tests/):
```sh
Running bin/readconf-test-unittest
✓ test __unittest_L111_C1
✓ test __unittest_L26_C1
✓ test __unittest_L52_C1
2023-03-30 07:14:24 +00:00
✓ test __unittest_L4_C1
Summary: 4 passed, 0 failed in 7 ms
```
2023-03-30 06:58:28 +00:00
## DUB
2023-03-26 01:00:06 +00:00
Add a dependency on `"readconf": "~>0.4.0"`