Compare commits
No commits in common. "dad3d356c66078ce9bc5046eca0b61bdf3c1a98c" and "ff887e06407cdd0f2b53c9c6e46ec146ec84a6b6" have entirely different histories.
dad3d356c6
...
ff887e0640
8 changed files with 27 additions and 143 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
// Используйте 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}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
"git": "/var/lib/snapd",
|
"git": "/var/lib/snapd",
|
||||||
"project": "/",
|
"project": "/"
|
||||||
"email": "user@site.domain"
|
|
||||||
}
|
}
|
||||||
|
|
16
source/app.d
16
source/app.d
|
@ -2,9 +2,7 @@ import snapd;
|
||||||
import commandr;
|
import commandr;
|
||||||
import std.file;
|
import std.file;
|
||||||
|
|
||||||
import std.stdio : writeln;
|
import core.stdc.stdlib : EXIT_SUCCESS;
|
||||||
|
|
||||||
import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE;
|
|
||||||
|
|
||||||
private string programName = "snapd";
|
private string programName = "snapd";
|
||||||
|
|
||||||
|
@ -20,16 +18,10 @@ int main(string[] args)
|
||||||
)
|
)
|
||||||
.parse(args);
|
.parse(args);
|
||||||
|
|
||||||
string configFile = argumets.option("config", "snapd.json");
|
string configFile = "snapd.json";
|
||||||
|
configFile = argumets.option("config", configFile);
|
||||||
|
|
||||||
SnapdConfig config;
|
auto sc = new SnapdConfig(configFile);
|
||||||
|
|
||||||
try {
|
|
||||||
config = new SnapdConfig(configFile);
|
|
||||||
} catch (SnapdConfigException e) {
|
|
||||||
e.print();
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,93 +0,0 @@
|
||||||
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; }
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
module snapd.config;
|
|
||||||
|
|
||||||
public import snapd.config.exception;
|
|
||||||
public import snapd.config.config;
|
|
|
@ -1,3 +1,3 @@
|
||||||
module snapd.version_;
|
module snapd.version_;
|
||||||
|
|
||||||
enum snapdVersion = "0.0.2";
|
enum snapdVersion = "0.0.1";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue