Сформирован базовый механизм чтения конфигурационного файла.

Необходимо читать файл конфигурации, который будет содержать пути к репозиторию git и проекту для отслеживания.
This commit is contained in:
Alexander Zhirov 2025-05-23 02:10:07 +03:00
parent bcfd2c49e5
commit ff887e0640
Signed by: alexander
GPG key ID: C8D8BE544A27C511
5 changed files with 39 additions and 0 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ snapd-test-*
*.o
*.obj
*.lst
bin

4
snapd.json Normal file
View file

@ -0,0 +1,4 @@
{
"git": "/var/lib/snapd",
"project": "/"
}

View file

@ -1,5 +1,6 @@
import snapd;
import commandr;
import std.file;
import core.stdc.stdlib : EXIT_SUCCESS;
@ -8,7 +9,19 @@ private string programName = "snapd";
int main(string[] args)
{
auto argumets = new Program(programName, snapdVersion)
.add(new Option("c", "config", "Сonfiguration file path")
.optional
.validateEachWith(
opt => opt.exists && opt.isFile,
"A JSON file path must be provided"
)
)
.parse(args);
string configFile = "snapd.json";
configFile = argumets.option("config", configFile);
auto sc = new SnapdConfig(configFile);
return EXIT_SUCCESS;
}

20
source/snapd/config.d Normal file
View file

@ -0,0 +1,20 @@
module snapd.config;
import std.json;
import std.file;
import std.stdio : writeln;
class SnapdConfig {
private string _git;
private string _project;
this(string configFile) {
string jsonText = readText(configFile);
auto jsonData = parseJSON(jsonText);
if ("gits" !in jsonData)
writeln("Ключ отсутствует");
writeln(jsonData["git"].str);
writeln(jsonData["project"].str);
}
}

View file

@ -1,3 +1,4 @@
module snapd;
public import snapd.version_;
public import snapd.config;