diff --git a/.gitignore b/.gitignore index 3986dde..07c2a16 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ snapd-test-* *.o *.obj *.lst +bin diff --git a/snapd.json b/snapd.json new file mode 100644 index 0000000..1dc307f --- /dev/null +++ b/snapd.json @@ -0,0 +1,4 @@ +{ + "git": "/var/lib/snapd", + "project": "/" +} diff --git a/source/app.d b/source/app.d index 497c1a8..b452dbf 100644 --- a/source/app.d +++ b/source/app.d @@ -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; } diff --git a/source/snapd/config.d b/source/snapd/config.d new file mode 100644 index 0000000..d093331 --- /dev/null +++ b/source/snapd/config.d @@ -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); + } +} diff --git a/source/snapd/package.d b/source/snapd/package.d index 45456d4..4f5e10f 100644 --- a/source/snapd/package.d +++ b/source/snapd/package.d @@ -1,3 +1,4 @@ module snapd; public import snapd.version_; +public import snapd.config;