mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
better commands
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
add_library(commands srcs/Command.cpp srcs/CommandDiff.cpp srcs/CommandList.cpp srcs/CommandListFiles.cpp srcs/CommandRestore.cpp srcs/CommandRun.cpp srcs/CommandsCommon.cpp srcs/Diff.cpp srcs/CommandMount.cpp)
|
||||
add_library(commands srcs/CommandDiff.cpp srcs/CommandList.cpp srcs/CommandListFiles.cpp srcs/CommandRestore.cpp srcs/CommandRun.cpp srcs/CommandsCommon.cpp srcs/Diff.cpp srcs/CommandMount.cpp)
|
||||
|
||||
target_include_directories(commands PUBLIC includes)
|
||||
|
||||
|
||||
@@ -14,14 +14,7 @@ public:
|
||||
virtual void run(Context ctx) = 0;
|
||||
|
||||
/// Default virtual destructor
|
||||
virtual ~Command() = 0;
|
||||
|
||||
/// The name of the command
|
||||
const std::string name;
|
||||
|
||||
protected:
|
||||
/// Constructs a command with name \p name
|
||||
Command(std::string name);
|
||||
virtual ~Command() = default;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ class CommandDiff : public Command {
|
||||
public:
|
||||
CommandDiff();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"diff"};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class CommandList : public Command {
|
||||
public:
|
||||
CommandList();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"list"};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class CommandListFiles : public Command {
|
||||
public:
|
||||
CommandListFiles();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"list-files"};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class CommandMount : public Command {
|
||||
public:
|
||||
CommandMount();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"mount"};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class CommandRestore : public Command {
|
||||
public:
|
||||
CommandRestore();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"restore"};
|
||||
|
||||
private:
|
||||
/// Internal function to restore a file
|
||||
|
||||
@@ -14,6 +14,7 @@ class CommandRun : public Command {
|
||||
public:
|
||||
CommandRun();
|
||||
void run(Context ctx) override;
|
||||
static constexpr std::string_view name{"run"};
|
||||
|
||||
private:
|
||||
/// Internal function to chunk the file and save it
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
//
|
||||
// Created by Stepan Usatiuk on 23.05.2023.
|
||||
//
|
||||
|
||||
#include "../includes/Command.h"
|
||||
|
||||
Command::Command(std::string name) : name(std::move(name)) {}
|
||||
|
||||
Command::~Command() = default;
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
using namespace CommandsCommon;
|
||||
|
||||
CommandDiff::CommandDiff() : Command("diff") {}
|
||||
CommandDiff::CommandDiff() : Command() {}
|
||||
|
||||
void CommandDiff::run(Context ctx) {
|
||||
std::string diffMode = ctx.repo->getConfig().getStr("diff-mode");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "../includes/CommandList.h"
|
||||
|
||||
CommandList::CommandList() : Command("list") {
|
||||
CommandList::CommandList() : Command() {
|
||||
}
|
||||
|
||||
void CommandList::run(Context ctx) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "../../repo/includes/objects/File.h"
|
||||
#include "../../utils/includes/BytesFormatter.h"
|
||||
|
||||
CommandListFiles::CommandListFiles() : Command("list-files") {
|
||||
CommandListFiles::CommandListFiles() : Command() {
|
||||
}
|
||||
|
||||
void CommandListFiles::run(Context ctx) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../includes/CommandMount.h"
|
||||
#include "RepoFS.h"
|
||||
|
||||
CommandMount::CommandMount() : Command("mount") {
|
||||
CommandMount::CommandMount() : Command() {
|
||||
}
|
||||
|
||||
void CommandMount::run(Context ctx) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
using namespace CommandsCommon;
|
||||
|
||||
CommandRestore::CommandRestore() : Command("restore") {
|
||||
CommandRestore::CommandRestore() : Command() {
|
||||
}
|
||||
|
||||
void CommandRestore::run(Context ctx) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
using namespace CommandsCommon;
|
||||
|
||||
CommandRun::CommandRun() : Command("run") {
|
||||
CommandRun::CommandRun() : Command() {
|
||||
}
|
||||
|
||||
void CommandRun::run(Context ctx) {
|
||||
|
||||
@@ -137,7 +137,10 @@ void RepoFS::start(Repository *repo, std::string path) {
|
||||
for (auto const &f: a.files) {
|
||||
auto file = Serialize::deserialize<File>(repo->getObject(f));
|
||||
// TODO: symlinks
|
||||
if (file.fileType == File::Type::Symlink) throw Exception("Symlinks not supported yet!");
|
||||
if (file.fileType == File::Type::Symlink) {
|
||||
std::cerr << "Symlinks not supported yet!" << std::endl;
|
||||
continue;
|
||||
}
|
||||
auto path = std::filesystem::u8path(file.name);
|
||||
DirEntry *entry = &(root.children[std::to_string(a.id)]);
|
||||
entry->isFakeDir = true;
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -109,12 +109,12 @@ int main(int argc, char *argv[]) {
|
||||
Context ctx{&logger, repo.get()};
|
||||
|
||||
std::unordered_map<std::string, std::unique_ptr<Command>> commands;
|
||||
commands.emplace(CommandDiff().name, std::make_unique<CommandDiff>());
|
||||
commands.emplace(CommandRestore().name, std::make_unique<CommandRestore>());
|
||||
commands.emplace(CommandRun().name, std::make_unique<CommandRun>());
|
||||
commands.emplace(CommandListFiles().name, std::make_unique<CommandListFiles>());
|
||||
commands.emplace(CommandList().name, std::make_unique<CommandList>());
|
||||
commands.emplace(CommandMount().name, std::make_unique<CommandMount>());
|
||||
commands.emplace(CommandDiff::name, std::make_unique<CommandDiff>());
|
||||
commands.emplace(CommandRestore::name, std::make_unique<CommandRestore>());
|
||||
commands.emplace(CommandRun::name, std::make_unique<CommandRun>());
|
||||
commands.emplace(CommandListFiles::name, std::make_unique<CommandListFiles>());
|
||||
commands.emplace(CommandList::name, std::make_unique<CommandList>());
|
||||
commands.emplace(CommandMount::name, std::make_unique<CommandMount>());
|
||||
|
||||
if (commands.count(opt) == 0) {
|
||||
std::cerr << "Unknown argument" << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user