From 3ffd5000e7d157508f583a5144a9826c3b03d287 Mon Sep 17 00:00:00 2001 From: Heaven Date: Tue, 12 May 2026 03:05:47 +0200 Subject: [PATCH] New commands!!! --- src/Output.cpp | 40 +++++++++++++++++++++++++++++++++++++--- src/Output.hpp | 4 ++++ src/main.cpp | 14 ++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/Output.cpp b/src/Output.cpp index 6241446..5f48abc 100644 --- a/src/Output.cpp +++ b/src/Output.cpp @@ -1,11 +1,12 @@ #include "Output.hpp" -#include +#include #include #include "fmt/base.h" #include "fmt/color.h" #include +#include #include namespace Output { @@ -15,10 +16,10 @@ namespace Output { 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_coral), + fmt::print(fmt::fg(fmt::color::light_green), " gen Generates CMakeLists.txt file.\n" ); - fmt::print(fmt::fg(fmt::color::light_coral), + fmt::print(fmt::fg(fmt::color::light_green), " build Run cmake and build.\n" ); fmt::print(fmt::fg(fmt::color::light_coral), @@ -72,4 +73,37 @@ namespace Output { 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; + } } diff --git a/src/Output.hpp b/src/Output.hpp index ff0198b..f0b1a54 100644 --- a/src/Output.hpp +++ b/src/Output.hpp @@ -1,7 +1,11 @@ #pragma once +#include + namespace Output { void printMenu(); void printArgClean(); void printArgVersion(); + + int executeCommand(const std::string& command, const std::string& successMsg); } diff --git a/src/main.cpp b/src/main.cpp index 97f6609..c4d3e4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include #include "Output.hpp" @@ -15,6 +16,19 @@ int main(int argc, char* argv[]) { return 0; } + if (std::string_view(argv[1]) == "gen") { + Output::executeCommand("cmkr gen", "Cmake generation completed :D"); + } + + if (std::string_view(argv[1]) == "install") { + Output::executeCommand("cmkr install", "CMake install completed :D"); + } + + // TODO: cmkr build with args + if (std::string_view(argv[1]) == "build") { + Output::executeCommand("cmkr build", "Cmake build completed :D"); + } + if (std::string_view(argv[1]) == "clean") { Output::printArgClean(); }