diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index b33d3ce..1461615 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -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) diff --git a/src/commands/includes/Command.h b/src/commands/includes/Command.h index f67dde9..2fd951a 100644 --- a/src/commands/includes/Command.h +++ b/src/commands/includes/Command.h @@ -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; }; diff --git a/src/commands/includes/CommandDiff.h b/src/commands/includes/CommandDiff.h index f77c3eb..7054a2c 100644 --- a/src/commands/includes/CommandDiff.h +++ b/src/commands/includes/CommandDiff.h @@ -17,6 +17,7 @@ class CommandDiff : public Command { public: CommandDiff(); void run(Context ctx) override; + static constexpr std::string_view name{"diff"}; }; diff --git a/src/commands/includes/CommandList.h b/src/commands/includes/CommandList.h index e173d92..9d46f96 100644 --- a/src/commands/includes/CommandList.h +++ b/src/commands/includes/CommandList.h @@ -14,6 +14,7 @@ class CommandList : public Command { public: CommandList(); void run(Context ctx) override; + static constexpr std::string_view name{"list"}; }; diff --git a/src/commands/includes/CommandListFiles.h b/src/commands/includes/CommandListFiles.h index 4aaeae1..29957f1 100644 --- a/src/commands/includes/CommandListFiles.h +++ b/src/commands/includes/CommandListFiles.h @@ -14,6 +14,7 @@ class CommandListFiles : public Command { public: CommandListFiles(); void run(Context ctx) override; + static constexpr std::string_view name{"list-files"}; }; diff --git a/src/commands/includes/CommandMount.h b/src/commands/includes/CommandMount.h index 53ec45d..ab2648d 100644 --- a/src/commands/includes/CommandMount.h +++ b/src/commands/includes/CommandMount.h @@ -11,6 +11,7 @@ class CommandMount : public Command { public: CommandMount(); void run(Context ctx) override; + static constexpr std::string_view name{"mount"}; }; diff --git a/src/commands/includes/CommandRestore.h b/src/commands/includes/CommandRestore.h index 5eb2e03..f6a7056 100644 --- a/src/commands/includes/CommandRestore.h +++ b/src/commands/includes/CommandRestore.h @@ -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 diff --git a/src/commands/includes/CommandRun.h b/src/commands/includes/CommandRun.h index 6e80cb7..4667b22 100644 --- a/src/commands/includes/CommandRun.h +++ b/src/commands/includes/CommandRun.h @@ -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 diff --git a/src/commands/srcs/Command.cpp b/src/commands/srcs/Command.cpp deleted file mode 100644 index 386d8e3..0000000 --- a/src/commands/srcs/Command.cpp +++ /dev/null @@ -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; \ No newline at end of file diff --git a/src/commands/srcs/CommandDiff.cpp b/src/commands/srcs/CommandDiff.cpp index dc504c2..c9c51db 100644 --- a/src/commands/srcs/CommandDiff.cpp +++ b/src/commands/srcs/CommandDiff.cpp @@ -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"); diff --git a/src/commands/srcs/CommandList.cpp b/src/commands/srcs/CommandList.cpp index f61e07a..9cb29ca 100644 --- a/src/commands/srcs/CommandList.cpp +++ b/src/commands/srcs/CommandList.cpp @@ -4,7 +4,7 @@ #include "../includes/CommandList.h" -CommandList::CommandList() : Command("list") { +CommandList::CommandList() : Command() { } void CommandList::run(Context ctx) { diff --git a/src/commands/srcs/CommandListFiles.cpp b/src/commands/srcs/CommandListFiles.cpp index a2b1995..2fb77de 100644 --- a/src/commands/srcs/CommandListFiles.cpp +++ b/src/commands/srcs/CommandListFiles.cpp @@ -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) { diff --git a/src/commands/srcs/CommandMount.cpp b/src/commands/srcs/CommandMount.cpp index e55ef6a..2d21c95 100644 --- a/src/commands/srcs/CommandMount.cpp +++ b/src/commands/srcs/CommandMount.cpp @@ -5,7 +5,7 @@ #include "../includes/CommandMount.h" #include "RepoFS.h" -CommandMount::CommandMount() : Command("mount") { +CommandMount::CommandMount() : Command() { } void CommandMount::run(Context ctx) { diff --git a/src/commands/srcs/CommandRestore.cpp b/src/commands/srcs/CommandRestore.cpp index f7de0a7..9541455 100644 --- a/src/commands/srcs/CommandRestore.cpp +++ b/src/commands/srcs/CommandRestore.cpp @@ -20,7 +20,7 @@ using namespace CommandsCommon; -CommandRestore::CommandRestore() : Command("restore") { +CommandRestore::CommandRestore() : Command() { } void CommandRestore::run(Context ctx) { diff --git a/src/commands/srcs/CommandRun.cpp b/src/commands/srcs/CommandRun.cpp index 96e37a9..31d499c 100644 --- a/src/commands/srcs/CommandRun.cpp +++ b/src/commands/srcs/CommandRun.cpp @@ -26,7 +26,7 @@ using namespace CommandsCommon; -CommandRun::CommandRun() : Command("run") { +CommandRun::CommandRun() : Command() { } void CommandRun::run(Context ctx) { diff --git a/src/fuse/srcs/RepoFS.cpp b/src/fuse/srcs/RepoFS.cpp index 712a5a5..295e6ba 100644 --- a/src/fuse/srcs/RepoFS.cpp +++ b/src/fuse/srcs/RepoFS.cpp @@ -137,7 +137,10 @@ void RepoFS::start(Repository *repo, std::string path) { for (auto const &f: a.files) { auto file = Serialize::deserialize(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; diff --git a/src/main.cpp b/src/main.cpp index 47934ab..b14a144 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,12 +109,12 @@ int main(int argc, char *argv[]) { Context ctx{&logger, repo.get()}; std::unordered_map> commands; - commands.emplace(CommandDiff().name, std::make_unique()); - commands.emplace(CommandRestore().name, std::make_unique()); - commands.emplace(CommandRun().name, std::make_unique()); - commands.emplace(CommandListFiles().name, std::make_unique()); - commands.emplace(CommandList().name, std::make_unique()); - commands.emplace(CommandMount().name, std::make_unique()); + commands.emplace(CommandDiff::name, std::make_unique()); + commands.emplace(CommandRestore::name, std::make_unique()); + commands.emplace(CommandRun::name, std::make_unique()); + commands.emplace(CommandListFiles::name, std::make_unique()); + commands.emplace(CommandList::name, std::make_unique()); + commands.emplace(CommandMount::name, std::make_unique()); if (commands.count(opt) == 0) { std::cerr << "Unknown argument" << std::endl;