better commands

This commit is contained in:
2023-07-14 22:26:18 +02:00
parent f240c313a7
commit b0522a6871
17 changed files with 24 additions and 31 deletions

View File

@@ -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)

View File

@@ -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;
};

View File

@@ -17,6 +17,7 @@ class CommandDiff : public Command {
public:
CommandDiff();
void run(Context ctx) override;
static constexpr std::string_view name{"diff"};
};

View File

@@ -14,6 +14,7 @@ class CommandList : public Command {
public:
CommandList();
void run(Context ctx) override;
static constexpr std::string_view name{"list"};
};

View File

@@ -14,6 +14,7 @@ class CommandListFiles : public Command {
public:
CommandListFiles();
void run(Context ctx) override;
static constexpr std::string_view name{"list-files"};
};

View File

@@ -11,6 +11,7 @@ class CommandMount : public Command {
public:
CommandMount();
void run(Context ctx) override;
static constexpr std::string_view name{"mount"};
};

View File

@@ -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

View 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

View File

@@ -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;

View File

@@ -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");

View File

@@ -4,7 +4,7 @@
#include "../includes/CommandList.h"
CommandList::CommandList() : Command("list") {
CommandList::CommandList() : Command() {
}
void CommandList::run(Context ctx) {

View File

@@ -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) {

View File

@@ -5,7 +5,7 @@
#include "../includes/CommandMount.h"
#include "RepoFS.h"
CommandMount::CommandMount() : Command("mount") {
CommandMount::CommandMount() : Command() {
}
void CommandMount::run(Context ctx) {

View File

@@ -20,7 +20,7 @@
using namespace CommandsCommon;
CommandRestore::CommandRestore() : Command("restore") {
CommandRestore::CommandRestore() : Command() {
}
void CommandRestore::run(Context ctx) {

View File

@@ -26,7 +26,7 @@
using namespace CommandsCommon;
CommandRun::CommandRun() : Command("run") {
CommandRun::CommandRun() : Command() {
}
void CommandRun::run(Context ctx) {

View File

@@ -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;

View File

@@ -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;