Сформирован базовый механизм чтения конфигурационного файла.
Необходимо читать файл конфигурации, который будет содержать пути к репозиторию git и проекту для отслеживания.
This commit is contained in:
parent
bcfd2c49e5
commit
ff887e0640
5 changed files with 39 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ snapd-test-*
|
||||||
*.o
|
*.o
|
||||||
*.obj
|
*.obj
|
||||||
*.lst
|
*.lst
|
||||||
|
bin
|
||||||
|
|
4
snapd.json
Normal file
4
snapd.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"git": "/var/lib/snapd",
|
||||||
|
"project": "/"
|
||||||
|
}
|
13
source/app.d
13
source/app.d
|
@ -1,5 +1,6 @@
|
||||||
import snapd;
|
import snapd;
|
||||||
import commandr;
|
import commandr;
|
||||||
|
import std.file;
|
||||||
|
|
||||||
import core.stdc.stdlib : EXIT_SUCCESS;
|
import core.stdc.stdlib : EXIT_SUCCESS;
|
||||||
|
|
||||||
|
@ -8,7 +9,19 @@ private string programName = "snapd";
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
auto argumets = new Program(programName, snapdVersion)
|
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);
|
.parse(args);
|
||||||
|
|
||||||
|
string configFile = "snapd.json";
|
||||||
|
configFile = argumets.option("config", configFile);
|
||||||
|
|
||||||
|
auto sc = new SnapdConfig(configFile);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
20
source/snapd/config.d
Normal file
20
source/snapd/config.d
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
module snapd;
|
module snapd;
|
||||||
|
|
||||||
public import snapd.version_;
|
public import snapd.version_;
|
||||||
|
public import snapd.config;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue