Skip to content

Commit

Permalink
Add makefs and openfs commands to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryKogan committed Dec 17, 2023
1 parent 01f7b44 commit 04a2513
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/CLI/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ auto CLI::execute(std::string const &command, std::vector<std::string> args) ->
help();
} else if (command == "clear") {
clear();
} else if (command == "makefs") {
makefs(std::move(args));
} else if (command == "openfs") {
openfs(std::move(args));
} else if (command == "fsinfo") {
fsinfo();
} else if (command == "dirname") {
Expand Down Expand Up @@ -86,6 +90,10 @@ auto CLI::help() -> void {
std::cout << "-\t'help' - show this message\n";
std::cout << "-\t'exit' - exit the program\n";
std::cout << "-\t'clear' - clear the screen\n";
std::cout << '\n';
std::cout << "-\t'makefs <path> <size> <cluster_size>' - create a new file system\n";
std::cout << "-\t'openfs <path>' - open an existing file system\n";
std::cout << '\n';
std::cout << "-\t'fsinfo' - show file system info\n";
std::cout << "-\t'dirname <path>' - get the directory portion of a pathname\n";
std::cout << "-\t'basename <path>' - get the filename portion of a pathname\n";
Expand Down Expand Up @@ -113,6 +121,28 @@ auto CLI::clear() -> void {
#endif
}

auto CLI::makefs(std::vector<std::string> args) -> void {
if (args.size() != 3) {
std::cout << "Wrong number of arguments. Usage: makefs <path> <size> <cluster_size>\n";
return;
}

std::string path = args[0];
std::uint64_t size = std::stoull(args[1]);
std::uint64_t cluster_size = std::stoull(args[2]);

FileSystem::make(path, {size, cluster_size});
}

auto CLI::openfs(std::vector<std::string> args) -> void {
if (args.size() != 1) {
std::cout << "Wrong number of arguments. Usage: openfs <path>\n";
return;
}

file_system_ = FileSystem(args[0]);
}

auto CLI::fsinfo() -> void { std::cout << file_system_ << '\n'; }

auto CLI::dirname(std::vector<std::string> args) -> void {
Expand Down
3 changes: 3 additions & 0 deletions src/CLI/CLI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class CLI {
static auto help() -> void;
static auto clear() -> void;

static auto makefs(std::vector<std::string> args) -> void;
auto openfs(std::vector<std::string> args) -> void;

auto fsinfo() -> void;
auto dirname(std::vector<std::string> args) -> void;
auto basename(std::vector<std::string> args) -> void;
Expand Down

0 comments on commit 04a2513

Please sign in to comment.