Изменение имени проекта
This commit is contained in:
parent
7714bc498e
commit
cc1a81261a
16 changed files with 70 additions and 70 deletions
24
source/app.d
24
source/app.d
|
@ -1,14 +1,14 @@
|
|||
import snapd;
|
||||
import snag;
|
||||
import commandr;
|
||||
import std.file;
|
||||
|
||||
import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE;
|
||||
|
||||
private string programName = "snapd";
|
||||
private string programName = "snag";
|
||||
|
||||
int main(string[] args)
|
||||
{
|
||||
auto argumets = new Program(programName, snapdVersion)
|
||||
auto argumets = new Program(programName, snagVersion)
|
||||
.add(new Command("init", "Initializing the repository for storing snapshots"))
|
||||
.add(new Command("status", "Checking the status of tracked files"))
|
||||
.add(new Command("create", "Create a new backup"))
|
||||
|
@ -21,31 +21,31 @@ int main(string[] args)
|
|||
)
|
||||
.parse(args);
|
||||
|
||||
string configFile = argumets.option("config", "snapd.json");
|
||||
string configFile = argumets.option("config", "snag.json");
|
||||
|
||||
SnapdConfig config;
|
||||
SnagConfig config;
|
||||
|
||||
try {
|
||||
config = new SnapdConfig(configFile);
|
||||
} catch (SnapdConfigException e) {
|
||||
config = new SnagConfig(configFile);
|
||||
} catch (SnagConfigException e) {
|
||||
e.print();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
auto snapd = new Snapd(config);
|
||||
auto snag = new Snag(config);
|
||||
|
||||
try {
|
||||
argumets
|
||||
.on("init", (init) {
|
||||
snapd.initialize();
|
||||
snag.initialize();
|
||||
})
|
||||
.on("status", (status) {
|
||||
snapd.status();
|
||||
snag.status();
|
||||
})
|
||||
.on("create", (create) {
|
||||
snapd.create();
|
||||
snag.create();
|
||||
});
|
||||
} catch (SnapdException e) {
|
||||
} catch (SnagException e) {
|
||||
e.print();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module snapd.config.config;
|
||||
module snag.config.config;
|
||||
|
||||
import std.json;
|
||||
import std.file;
|
||||
|
@ -6,9 +6,9 @@ import std.path;
|
|||
import std.regex;
|
||||
import std.string;
|
||||
|
||||
import snapd.config.exception;
|
||||
import snag.config.exception;
|
||||
|
||||
class SnapdConfig {
|
||||
class SnagConfig {
|
||||
private string _git;
|
||||
private string _project;
|
||||
private string _email;
|
||||
|
@ -27,75 +27,75 @@ class SnapdConfig {
|
|||
jsonText = readText(configFile);
|
||||
jsonData = parseJSON(jsonText);
|
||||
} catch (Exception e) {
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"An error occurred while reading the configuration file:\n\t"
|
||||
~ e.msg
|
||||
);
|
||||
}
|
||||
|
||||
if ("git" !in jsonData)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The configuration file is missing the \"git\" parameter"
|
||||
);
|
||||
|
||||
_git = jsonData["git"].str;
|
||||
|
||||
if (!_git.length)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"git\" parameter must contain the path to the directory"
|
||||
);
|
||||
|
||||
if (!_git.isAbsolute)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"git\" parameter must be an absolute path to the directory:\n\t"
|
||||
~ _git
|
||||
);
|
||||
|
||||
if ("project" !in jsonData)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The configuration file is missing the \"project\" parameter"
|
||||
);
|
||||
|
||||
_project = jsonData["project"].str;
|
||||
|
||||
if (!_project.length)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"project\" parameter must contain the path to the directory"
|
||||
);
|
||||
|
||||
if (!_project.isAbsolute)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"project\" parameter must be an absolute path to the directory:\n\t"
|
||||
~ _project
|
||||
);
|
||||
|
||||
if ("email" !in jsonData)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The configuration file is missing the \"email\" parameter"
|
||||
);
|
||||
|
||||
_email = jsonData["email"].str;
|
||||
|
||||
if (!_email.length)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"email\" parameter must contain an email address"
|
||||
);
|
||||
|
||||
if (!isValidEmail(_email))
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"Invalid email address provided in the \"email\" parameter:\n\t"
|
||||
~ _email
|
||||
);
|
||||
|
||||
if ("user" !in jsonData)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The configuration file is missing the \"user\" parameter"
|
||||
);
|
||||
|
||||
_user = jsonData["user"].str;
|
||||
|
||||
if (!_user.length)
|
||||
throw new SnapdConfigException(
|
||||
throw new SnagConfigException(
|
||||
"The \"user\" parameter must contain an user name"
|
||||
);
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
module snapd.config.exception;
|
||||
module snag.config.exception;
|
||||
|
||||
import std.exception;
|
||||
import std.stdio : writeln;
|
||||
|
||||
class SnapdConfigException : Exception {
|
||||
class SnagConfigException : Exception {
|
||||
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
||||
super(msg, file, line);
|
||||
}
|
4
source/snag/config/package.d
Normal file
4
source/snag/config/package.d
Normal file
|
@ -0,0 +1,4 @@
|
|||
module snag.config;
|
||||
|
||||
public import snag.config.exception;
|
||||
public import snag.config.config;
|
|
@ -1,6 +1,6 @@
|
|||
module snapd.core.core;
|
||||
module snag.core.core;
|
||||
|
||||
import snapd.config;
|
||||
import snag.config;
|
||||
import std.format;
|
||||
import std.stdio;
|
||||
import std.array;
|
||||
|
@ -9,7 +9,7 @@ import std.process;
|
|||
import std.algorithm;
|
||||
import std.string;
|
||||
|
||||
class SnapdException : Exception {
|
||||
class SnagException : Exception {
|
||||
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
||||
super(msg, file, line);
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ class SnapdException : Exception {
|
|||
}
|
||||
}
|
||||
|
||||
class Snapd {
|
||||
class Snag {
|
||||
private string[] _baseCommand;
|
||||
private SnapdConfig _config;
|
||||
private SnagConfig _config;
|
||||
|
||||
this(SnapdConfig config) {
|
||||
this(SnagConfig config) {
|
||||
_baseCommand = format(
|
||||
"git --git-dir=%s --work-tree=%s",
|
||||
config.git, config.project
|
||||
|
@ -34,7 +34,7 @@ class Snapd {
|
|||
void initialize() {
|
||||
auto result = execute(_baseCommand ~ "init");
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"A Git repository initialization error occurred:\n"
|
||||
~ result.output
|
||||
);
|
||||
|
@ -43,7 +43,7 @@ class Snapd {
|
|||
_baseCommand ~ ["config", "user.email", _config.email]
|
||||
);
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"A Git repository initialization error occurred:\n"
|
||||
~ result.output
|
||||
);
|
||||
|
@ -52,7 +52,7 @@ class Snapd {
|
|||
_baseCommand ~ ["config", "user.name", _config.user]
|
||||
);
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"A Git repository initialization error occurred:\n"
|
||||
~ result.output
|
||||
);
|
||||
|
@ -68,7 +68,7 @@ class Snapd {
|
|||
_baseCommand ~ ["status", "--porcelain"]
|
||||
);
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"An error occurred while checking the file tracking status:\n"
|
||||
~ result.output
|
||||
);
|
||||
|
@ -90,7 +90,7 @@ class Snapd {
|
|||
_baseCommand ~ ["add", "."]
|
||||
);
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"Failed to prepare files for archiving:\n"
|
||||
~ result.output
|
||||
);
|
||||
|
@ -99,7 +99,7 @@ class Snapd {
|
|||
_baseCommand ~ ["commit", "-m", "test"]
|
||||
);
|
||||
if (result.status)
|
||||
throw new SnapdException(
|
||||
throw new SnagException(
|
||||
"Failed to create a backup:\n"
|
||||
~ result.output
|
||||
);
|
3
source/snag/core/package.d
Normal file
3
source/snag/core/package.d
Normal file
|
@ -0,0 +1,3 @@
|
|||
module snag.core;
|
||||
|
||||
public import snag.core.core;
|
5
source/snag/package.d
Normal file
5
source/snag/package.d
Normal file
|
@ -0,0 +1,5 @@
|
|||
module snag;
|
||||
|
||||
public import snag.version_;
|
||||
public import snag.config;
|
||||
public import snag.core;
|
3
source/snag/version_.d
Normal file
3
source/snag/version_.d
Normal file
|
@ -0,0 +1,3 @@
|
|||
module snag.version_;
|
||||
|
||||
enum snagVersion = "0.0.4";
|
|
@ -1,4 +0,0 @@
|
|||
module snapd.config;
|
||||
|
||||
public import snapd.config.exception;
|
||||
public import snapd.config.config;
|
|
@ -1,3 +0,0 @@
|
|||
module snapd.core;
|
||||
|
||||
public import snapd.core.core;
|
|
@ -1,5 +0,0 @@
|
|||
module snapd;
|
||||
|
||||
public import snapd.version_;
|
||||
public import snapd.config;
|
||||
public import snapd.core;
|
|
@ -1,3 +0,0 @@
|
|||
module snapd.version_;
|
||||
|
||||
enum snapdVersion = "0.0.3";
|
Loading…
Add table
Add a link
Reference in a new issue