v0.3.0-dev.8
This commit is contained in:
parent
1368b271b0
commit
1d89b62354
|
@ -5,9 +5,10 @@
|
||||||
<h1 align="center">readconf</h1>
|
<h1 align="center">readconf</h1>
|
||||||
|
|
||||||
[![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)
|
[![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)
|
||||||
[![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)](https://git.zhirov.kz/dlang/readconf)
|
[![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)](https://github.com/AlexanderZhirov/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)](https://code.dlang.org/packages/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/)
|
||||||
|
|
||||||
Singleton for reading the configuration file required for your program.
|
Singleton for reading the configuration file required for your program.
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,10 @@ import std.meta;
|
||||||
import singlog;
|
import singlog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read config object
|
* **Get an object to read the configuration file**
|
||||||
|
*
|
||||||
|
* - The `read()` will allow you to read the configuration file
|
||||||
|
* - `cf()` or `configFile()` will allow you to refer to the read file to get the parameters
|
||||||
*/
|
*/
|
||||||
alias rc = Config.file;
|
alias rc = Config.file;
|
||||||
|
|
||||||
|
@ -17,13 +20,13 @@ class Config
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum {
|
enum {
|
||||||
GROUP_PROPERTY = 4,
|
GROUP_PARAMETER = 4,
|
||||||
GROUP_VALUE_1 = 11, // string
|
GROUP_VALUE_1 = 11, // string
|
||||||
GROUP_VALUE_2 = 14, // "strin"
|
GROUP_VALUE_2 = 14, // "strin"
|
||||||
GROUP_VALUE_3 = 16, // 'string'
|
GROUP_VALUE_3 = 16, // 'string'
|
||||||
GROUP_SECTION_OTHER_OUTER = 17, // "[string]"
|
GROUP_SECTION_OTHER_OUTER = 17, // [string]
|
||||||
GROUP_SECTION_OTHER_INNER = 18, // "[string]"
|
GROUP_SECTION_OTHER_INNER = 18, // string
|
||||||
GROUP_SECTION_MAIN = 20, // "[]"
|
GROUP_SECTION_MAIN = 20, // []
|
||||||
}
|
}
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
|
@ -86,7 +89,7 @@ private:
|
||||||
else if (match[group][0] == '\'')
|
else if (match[group][0] == '\'')
|
||||||
group = GROUP_VALUE_3;
|
group = GROUP_VALUE_3;
|
||||||
|
|
||||||
this.configs[configName].add(sectionName, ConfigParameter(match[GROUP_PROPERTY], match[group]));
|
this.configs[configName].add(sectionName, ConfigParameter(match[GROUP_PARAMETER], match[group]));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -121,6 +124,8 @@ public:
|
||||||
* Read the configuration file
|
* Read the configuration file
|
||||||
* Params:
|
* Params:
|
||||||
* path = the path to the configuration file
|
* path = the path to the configuration file
|
||||||
|
* configName = a specific name to bind to the configuration file (default file name)
|
||||||
|
* Returns: `true` if the file was read successfully
|
||||||
*/
|
*/
|
||||||
bool read(string path, string configName = "")
|
bool read(string path, string configName = "")
|
||||||
{
|
{
|
||||||
|
@ -135,9 +140,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the section
|
* Accessing the read configuration file
|
||||||
* Params:
|
* Params:
|
||||||
* section = section name (default main "[]")
|
* configName = specific name to bind to the configuration file
|
||||||
|
* (if the read files are > 1, then specify a specific name, otherwise default file name)
|
||||||
|
* Returns: configuration file object ConfigFile
|
||||||
*/
|
*/
|
||||||
@property ConfigFile configFile(string configName = "")
|
@property ConfigFile configFile(string configName = "")
|
||||||
{
|
{
|
||||||
|
@ -153,11 +160,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config file
|
* Get the read configuration file
|
||||||
*
|
|
||||||
* Get the config file
|
|
||||||
* Params:
|
* Params:
|
||||||
* configName = config name (by default the name of the configuration file)
|
* configName = specific name to bind to the configuration file
|
||||||
|
* (if the read files are > 1, then specify a specific name, otherwise default file name)
|
||||||
|
* Returns: configuration file object ConfigFile
|
||||||
*/
|
*/
|
||||||
alias cf = configFile;
|
alias cf = configFile;
|
||||||
|
|
||||||
|
@ -189,7 +196,8 @@ struct ConfigFile
|
||||||
/**
|
/**
|
||||||
* Get the section
|
* Get the section
|
||||||
* Params:
|
* Params:
|
||||||
* section = section name (default main "[]")
|
* section = section name (default main section)
|
||||||
|
* Returns: the object of the configuration file section ConfigSection
|
||||||
*/
|
*/
|
||||||
@property ConfigSection sectionName(string section = mainSection)
|
@property ConfigSection sectionName(string section = mainSection)
|
||||||
{
|
{
|
||||||
|
@ -203,11 +211,10 @@ struct ConfigFile
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section name
|
|
||||||
*
|
|
||||||
* Get the section
|
* Get the section
|
||||||
* Params:
|
* Params:
|
||||||
* section = section name (default main "[]")
|
* section = section name (default main section)
|
||||||
|
* Returns: the object of the configuration file section ConfigSection
|
||||||
*/
|
*/
|
||||||
alias sn = sectionName;
|
alias sn = sectionName;
|
||||||
|
|
||||||
|
@ -249,7 +256,7 @@ struct ConfigSection
|
||||||
* Get the parameter value
|
* Get the parameter value
|
||||||
* Params:
|
* Params:
|
||||||
* key = parameter from the configuration file
|
* key = parameter from the configuration file
|
||||||
* Returns: the value of the parameter in the PP structure view
|
* Returns: the object of the parameter ConfigParameter
|
||||||
*/
|
*/
|
||||||
ConfigParameter key(string key)
|
ConfigParameter key(string key)
|
||||||
{
|
{
|
||||||
|
@ -262,7 +269,7 @@ struct ConfigSection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all keys and their values
|
* Get all keys and their values
|
||||||
* Returns: collection of properties structures PP
|
* Returns: collection of parameters
|
||||||
*/
|
*/
|
||||||
ConfigParameter[string] keys()
|
ConfigParameter[string] keys()
|
||||||
{
|
{
|
||||||
|
@ -286,9 +293,6 @@ struct ConfigSection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parameter and its value with the ability to convert to the desired data type
|
|
||||||
*/
|
|
||||||
struct ConfigParameter
|
struct ConfigParameter
|
||||||
{
|
{
|
||||||
private string property;
|
private string property;
|
||||||
|
|
Loading…
Reference in New Issue