#include "Output.hpp" #include #include #include "fmt/base.h" #include "fmt/color.h" #include #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"); fmt::print(fmt::fg(fmt::color::light_coral), " init [executable|library|shared|static|interface] Starts a new project in the same directory.\n" ); fmt::print(fmt::fg(fmt::color::light_green), " gen Generates CMakeLists.txt file.\n" ); fmt::print(fmt::fg(fmt::color::light_green), " build Run cmake and build.\n" ); fmt::print(fmt::fg(fmt::color::light_golden_rod_yellow), " run Run build.\n" ); fmt::print(fmt::fg(fmt::color::light_coral), " install Run cmake --install. Needs admin privileges.\n" ); fmt::print(fmt::fg(fmt::color::light_green), " clean Clean the build directory.\n" ); fmt::print(fmt::fg(fmt::color::light_green), " help Show help.\n" ); fmt::print(fmt::fg(fmt::color::light_green), " version Current cmkr version.\n" ); } void printArgClean() { // std::filesystem::path dirPath = "build"; // std::error_code errorCode; // 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 (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" ); } } void printArgVersion() { fmt::print("Version: 0.0.1 (Early pre-pre-pre-pre alpha\n"); } int executeCommand(const std::string& command, const std::string& successMsg) { FILE* pipe = popen(command.c_str(), "r"); if (!pipe) { fmt::print(fmt::fg(fmt::color::light_coral), "[Lazymake] Error! Could not execute command :(\n" ); return -1; } char buffer[256]; while (fgets(buffer, sizeof(buffer), pipe) != nullptr) { fmt::print("{}", buffer); // std::string line(buffer); // std::string target = "[cmkr]"; // size_t pos = line.find(target); // if (pos != std::string::npos) { // line.erase(pos, target.length() + 1); // fmt::print("{}", line); // } else { // fmt::print("{}", buffer); // } } int status = pclose(pipe); fmt::print(fmt::fg(fmt::color::light_green), "[Lazymake] {}\n", successMsg ); return status; } void runBuild() { if (checkValidBuildDir()) { fmt::print("FOUND BUILD FOLDER\n"); std::system("./build/lmake"); fmt::print("333FOUND BUILD FOLDER2\n"); } } }