From cca309db3e3c77609787e15488c07820733923ad Mon Sep 17 00:00:00 2001 From: Heaven Date: Tue, 12 May 2026 17:01:50 +0200 Subject: [PATCH] Progressing --- src/Output.cpp | 73 +++++++++++++++++++++++++++++++++----------------- src/Output.hpp | 3 +++ src/main.cpp | 4 +++ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/Output.cpp b/src/Output.cpp index 5f48abc..3acf3e4 100644 --- a/src/Output.cpp +++ b/src/Output.cpp @@ -9,7 +9,22 @@ #include #include +namespace { + std::filesystem::path buildDir = "build"; + std::error_code errorCode; +} + namespace Output { + bool checkValidBuildDir() { + if (!std::filesystem::exists(buildDir, errorCode) || !std::filesystem::is_directory(buildDir, errorCode)) { + fmt::print(fmt::fg(fmt::color::light_coral), + "[Lazymake] Cleanup failed. Nothing to clean :(\n" + ); + return false; + } + return true; + } + void printMenu() { fmt::print("Usage: lmake [arguments]\n"); fmt::print("arguments:\n"); @@ -22,7 +37,7 @@ namespace Output { fmt::print(fmt::fg(fmt::color::light_green), " build Run cmake and build.\n" ); - fmt::print(fmt::fg(fmt::color::light_coral), + fmt::print(fmt::fg(fmt::color::light_golden_rod_yellow), " run Run build.\n" ); fmt::print(fmt::fg(fmt::color::light_coral), @@ -40,34 +55,36 @@ namespace Output { } void printArgClean() { - std::filesystem::path dirPath = "build"; - std::error_code errorCode; + // std::filesystem::path dirPath = "build"; + // std::error_code errorCode; - if (!std::filesystem::exists(dirPath, errorCode) || !std::filesystem::is_directory(dirPath, errorCode)) { - fmt::print(fmt::fg(fmt::color::light_coral), - "[Lazymake] Cleanup failed. Nothing to clean :(\n" - ); - return; - } - - std::filesystem::remove_all(dirPath, errorCode); - - // for (const auto& entry : std::filesystem::directory_iterator(dirPath)) { - // std::filesystem::remove_all(entry.path()); + // if (!std::filesystem::exists(buildDir, errorCode) || !std::filesystem::is_directory(buildDir, errorCode)) { + // fmt::print(fmt::fg(fmt::color::light_coral), + // "[Lazymake] Cleanup failed. Nothing to clean :(\n" + // ); + // return; // } - if (errorCode) { - fmt::print(fmt::fg(fmt::color::light_coral), - "[Lazymake] Error! Could not clean up build directory :(\n {}\n", errorCode.message() + if (checkValidBuildDir()) { + std::filesystem::remove_all(buildDir, errorCode); + + // for (const auto& entry : std::filesystem::directory_iterator(dirPath)) { + // std::filesystem::remove_all(entry.path()); + // } + + if (errorCode) { + fmt::print(fmt::fg(fmt::color::light_coral), + "[Lazymake] Error! Could not clean up build directory :(\n {}\n", errorCode.message() + ); + return; + } + + std::filesystem::create_directory(buildDir, errorCode); + + fmt::print(fmt::fg(fmt::color::light_green), + "[Lazymake] Cleaned up build directory :D\n" ); - return; } - - std::filesystem::create_directory(dirPath, errorCode); - - fmt::print(fmt::fg(fmt::color::light_green), - "[Lazymake] Cleaned up build directory :D\n" - ); } void printArgVersion() { @@ -106,4 +123,12 @@ namespace Output { ); return status; } + + void runBuild() { + if (checkValidBuildDir()) { + fmt::print("FOUND BUILD FOLDER\n"); + std::system("./build/lmake"); + fmt::print("333FOUND BUILD FOLDER2\n"); + } + } } diff --git a/src/Output.hpp b/src/Output.hpp index f0b1a54..fac3015 100644 --- a/src/Output.hpp +++ b/src/Output.hpp @@ -3,9 +3,12 @@ #include namespace Output { + bool checkValidBuildDir(); + void printMenu(); void printArgClean(); void printArgVersion(); int executeCommand(const std::string& command, const std::string& successMsg); + void runBuild(); } diff --git a/src/main.cpp b/src/main.cpp index 6523f6e..a21e98a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,10 @@ int main(int argc, char* argv[]) { Output::executeCommand("cmkr build", "Cmake build completed :D"); } + if (std::string_view(argv[1]) == "run") { + Output::runBuild(); + } + if (std::string_view(argv[1]) == "clean") { Output::printArgClean(); }