snag/source/app.d
Alexander Zhirov 4301c27ca9
Добавлена новая команда diff для просмотра внесенных изменений на текущий момент.
Добавлена возможность установки комментария, имени автора, электронной почты при создании снимка.
Функции проверок через регулярные выражения перенесены в новый модуль lib.
2025-05-25 18:34:52 +03:00

111 lines
2.4 KiB
D
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import snag;
import commandr;
import std.file;
import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE;
private string programName = "snag";
int main(string[] args)
{
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("diff", "Show changed data"))
.add(new Command("create", "Create a new snapshot")
.add(new Option("c", "comment", "Specify comment")
.optional
.validateEachWith(
opt => opt.length > 0,
"cannot be empty"
)
)
.add(new Option("a", "author", "Specify author")
.optional
.validateEachWith(
opt => opt.length > 0,
"cannot be empty"
)
)
.add(new Option("e", "email", "Specify email")
.optional
.validateEachWith(
opt => opt.isValidEmail,
"must contain an email address"
)
)
)
.add(new Command("list", "List of snapshots")
.add(new Flag("c", "comment", "Show comment")
.name("comment")
.optional
)
.add(new Flag("a", "author", "Show author")
.name("author")
.optional
)
.add(new Flag("e", "email", "Show email")
.name("email")
.optional
)
)
.add(new Command("restore", "Restore to the specified snapshot state")
.add(new Argument("hash", "hash").required)
)
.add(new Option("c", "config", "Сonfiguration file path")
.optional
.validateEachWith(
opt => opt.exists && opt.isFile,
"must specify the path to the JSON file"
)
)
.parse(args);
string configFile = argumets.option("config", "snag.json");
SnagConfig config;
try {
config = new SnagConfig(configFile);
} catch (SnagConfigException e) {
e.print();
return EXIT_FAILURE;
}
auto snag = new Snag(config);
import std.stdio;
try {
argumets
.on("init", init =>
snag.initialize()
)
.on("diff", diff =>
snag.diff()
)
.on("status", status =>
snag.status()
)
.on("create", create =>
snag.create(
create.option("comment", ""),
create.option("author", ""),
create.option("email", "")
)
)
.on("list", list =>
snag.list(
list.flag("comment"),
list.flag("author"),
list.flag("email")
)
)
.on("restore", restore =>
snag.restore(restore.arg("hash"))
);
} catch (SnagException e) {
e.print();
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}