From 72f132b8fb9f2a47b0f723f4dc4eaa4fdb0c45bd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Apr 2025 08:22:28 +0200 Subject: dev: Improve makefile, add BTB_POSIX, and BTB_WINDOWS macro. - Refactor library code for better maintenance. - Improve code quality by using well known macros for status code. - Don't let the CLI pass when '-' is being passed as argument and is not recognized. Signed-off-by: Amlal El Mahrouss --- cli/CommandLine.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'cli') diff --git a/cli/CommandLine.cc b/cli/CommandLine.cc index 8c93898..5c522e7 100644 --- a/cli/CommandLine.cc +++ b/cli/CommandLine.cc @@ -7,13 +7,13 @@ #include #include -static bool kFailed = false; +static bool kFailed = false; static bool kDryRun = false; int main(int argc, char** argv) { if (argc <= 1) - return 1; + return EXIT_FAILURE; for (size_t index = 1; index < argc; ++index) { @@ -22,10 +22,10 @@ int main(int argc, char** argv) if (index_path == "-v" || index_path == "--version") { - logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; - logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; + BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; + BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; - logger::info() << "Bugs, Issues?, check out: https://github.com/amlel-el-mahrouss/btb/issues\n"; + BTB::Logger::info() << "Bugs, issues? Check out: https://github.com/nekernel-org/btb/issues\n"; return EXIT_SUCCESS; } @@ -37,19 +37,26 @@ int main(int argc, char** argv) else if (index_path == "-h" || index_path == "--help") { - logger::info() << "Usage: btb \n"; + BTB::Logger::info() << "Usage: btb \n"; return EXIT_SUCCESS; } + if (index_path.starts_with("-")) + { + BTB::Logger::info() << "error: unknown option '" << index_path << "'\n"; + + return EXIT_FAILURE; + } + std::thread job_build_thread([](std::string index_path) -> void { - IManifestBuilder* builder = nullptr; + BTB::IManifestBuilder* builder = nullptr; const auto kJsonExtension = ".json"; if (index_path.ends_with(kJsonExtension)) { - builder = new JSONManifestBuilder(); + builder = new BTB::JSONManifestBuilder(); if (!builder) { @@ -59,12 +66,12 @@ int main(int argc, char** argv) } else { - logger::info() << "error: file '" << index_path << "' does not end with .json!" << std::endl; + BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" << std::endl; kFailed = true; return; } - logger::info() << "building: " << index_path << std::endl; + BTB::Logger::info() << "building manifest: " << index_path << std::endl; if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { @@ -73,7 +80,8 @@ int main(int argc, char** argv) delete builder; builder = nullptr; - }, index_path); + }, + index_path); job_build_thread.join(); } -- cgit v1.2.3