54 lines
1.1 KiB
D
54 lines
1.1 KiB
D
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("create", "Create a new backup"))
|
||
.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 = 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);
|
||
|
||
try {
|
||
argumets
|
||
.on("init", (init) {
|
||
snag.initialize();
|
||
})
|
||
.on("status", (status) {
|
||
snag.status();
|
||
})
|
||
.on("create", (create) {
|
||
snag.create();
|
||
});
|
||
} catch (SnagException e) {
|
||
e.print();
|
||
return EXIT_FAILURE;
|
||
}
|
||
|
||
return EXIT_SUCCESS;
|
||
}
|