From c1051c850739b8f7b319aa1bc4c2b483428fcc38 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 23 May 2025 20:45:48 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20vscode=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..400e7c1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Используйте IntelliSense, чтобы узнать о возможных атрибутах. + // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов. + // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "code-d", + "request": "launch", + "dubBuild": true, + "name": "Build & Debug DUB project", + "cwd": "${command:dubWorkingDirectory}", + "program": "bin/${command:dubTarget}" + } + ] +} \ No newline at end of file From 3cb714f5445b02e53c22b9b98750bb0e6e759727 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 23 May 2025 20:46:23 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snapd.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snapd.json b/snapd.json index 1dc307f..d8b0536 100644 --- a/snapd.json +++ b/snapd.json @@ -1,4 +1,5 @@ { - "git": "/var/lib/snapd", - "project": "/" + "git": "/var/lib/snapd", + "project": "/", + "email": "user@site.domain" } From 309a47ea3a011dd88e91f1b53d73115e909e042b Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 23 May 2025 20:47:04 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B1=D1=8B=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20=D0=B2=20=D0=B4=D0=B8=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snapd/config.d | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 source/snapd/config.d diff --git a/source/snapd/config.d b/source/snapd/config.d deleted file mode 100644 index d093331..0000000 --- a/source/snapd/config.d +++ /dev/null @@ -1,20 +0,0 @@ -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); - } -} From f1d1bce20b8250f89d725b60dbedd13d8ce12bae Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 23 May 2025 20:47:53 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8,=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D1=8E=D1=89?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=B2=D0=BE=D0=B7=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BD=D0=BE=D0=B2=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snapd/config/config.d | 93 +++++++++++++++++++++++++++++++++ source/snapd/config/exception.d | 14 +++++ source/snapd/config/package.d | 4 ++ 3 files changed, 111 insertions(+) create mode 100644 source/snapd/config/config.d create mode 100644 source/snapd/config/exception.d create mode 100644 source/snapd/config/package.d diff --git a/source/snapd/config/config.d b/source/snapd/config/config.d new file mode 100644 index 0000000..5822758 --- /dev/null +++ b/source/snapd/config/config.d @@ -0,0 +1,93 @@ +module snapd.config.config; + +import std.json; +import std.file; +import std.path; +import std.regex; +import std.string; + +import snapd.config.exception; + +class SnapdConfig { + private string _git; + private string _project; + private string _email; + + private bool isValidEmail(string email) { + auto emailPattern = ctRegex!r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; + return !matchFirst(email, emailPattern).empty; + } + + this(string configFile) { + string jsonText; + JSONValue jsonData; + + try { + jsonText = readText(configFile); + jsonData = parseJSON(jsonText); + } catch (Exception e) { + throw new SnapdConfigException( + "An error occurred while reading the configuration file:\n\t" + ~ e.msg + ); + } + + if ("git" !in jsonData) + throw new SnapdConfigException( + "The configuration file is missing the \"git\" parameter" + ); + + _git = jsonData["git"].str; + + if (!_git.length) + throw new SnapdConfigException( + "The \"git\" parameter must contain the path to the directory" + ); + + if (!_git.isAbsolute) + throw new SnapdConfigException( + "The \"git\" parameter must be an absolute path to the directory:\n\t" + ~ _git + ); + + if ("project" !in jsonData) + throw new SnapdConfigException( + "The configuration file is missing the \"project\" parameter" + ); + + _project = jsonData["project"].str; + + if (!_project.length) + throw new SnapdConfigException( + "The \"project\" parameter must contain the path to the directory" + ); + + if (!_project.isAbsolute) + throw new SnapdConfigException( + "The \"project\" parameter must be an absolute path to the directory:\n\t" + ~ _project + ); + + if ("email" !in jsonData) + throw new SnapdConfigException( + "The configuration file is missing the \"email\" parameter" + ); + + _email = jsonData["email"].str; + + if (!_email.length) + throw new SnapdConfigException( + "The \"email\" parameter must contain an email address" + ); + + if (!isValidEmail(_email)) + throw new SnapdConfigException( + "Invalid email address provided in the \"email\" parameter:\n\t" + ~ _email + ); + } + + @property string git() const { return _git; } + @property string project() const { return _project; } + @property string email() const { return _email; } +} diff --git a/source/snapd/config/exception.d b/source/snapd/config/exception.d new file mode 100644 index 0000000..1abc0e5 --- /dev/null +++ b/source/snapd/config/exception.d @@ -0,0 +1,14 @@ +module snapd.config.exception; + +import std.exception; +import std.stdio : writeln; + +class SnapdConfigException : Exception { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + + void print() { + writeln(msg); + } +} diff --git a/source/snapd/config/package.d b/source/snapd/config/package.d new file mode 100644 index 0000000..5dd2aed --- /dev/null +++ b/source/snapd/config/package.d @@ -0,0 +1,4 @@ +module snapd.config; + +public import snapd.config.exception; +public import snapd.config.config; From dad3d356c66078ce9bc5046eca0b61bdf3c1a98c Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 23 May 2025 20:48:14 +0300 Subject: [PATCH 5/5] 0.0.2 --- source/app.d | 16 ++++++++++++---- source/snapd/version_.d | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/app.d b/source/app.d index b452dbf..3ac5b7a 100644 --- a/source/app.d +++ b/source/app.d @@ -2,7 +2,9 @@ import snapd; import commandr; import std.file; -import core.stdc.stdlib : EXIT_SUCCESS; +import std.stdio : writeln; + +import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE; private string programName = "snapd"; @@ -18,10 +20,16 @@ int main(string[] args) ) .parse(args); - string configFile = "snapd.json"; - configFile = argumets.option("config", configFile); + string configFile = argumets.option("config", "snapd.json"); - auto sc = new SnapdConfig(configFile); + SnapdConfig config; + + try { + config = new SnapdConfig(configFile); + } catch (SnapdConfigException e) { + e.print(); + return EXIT_FAILURE; + } return EXIT_SUCCESS; } diff --git a/source/snapd/version_.d b/source/snapd/version_.d index e09faec..98d0114 100644 --- a/source/snapd/version_.d +++ b/source/snapd/version_.d @@ -1,3 +1,3 @@ module snapd.version_; -enum snapdVersion = "0.0.1"; +enum snapdVersion = "0.0.2";