From 86310533f3142aad7d52d1b92d2dd9da65ede5b4 Mon Sep 17 00:00:00 2001 From: Jon-Michael Hartway Date: Thu, 2 Nov 2023 23:55:31 -0400 Subject: [PATCH] refactored some stuff and added clean command --- src/Command/Command.hpp | 1 + src/Command/CommandClean.cpp | 14 ++++++++++++++ src/Command/CommandGeneral.cpp | 8 +++----- src/Command/CommandInit.cpp | 10 ---------- src/Command/Interface.cpp | 16 ++++++++++++---- src/Generators/CMakeGenerator.cpp | 3 --- src/Generators/ConfigTomlGenerator.cpp | 5 ----- 7 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 src/Command/CommandClean.cpp diff --git a/src/Command/Command.hpp b/src/Command/Command.hpp index 7b80a0c..6023fdf 100644 --- a/src/Command/Command.hpp +++ b/src/Command/Command.hpp @@ -110,6 +110,7 @@ namespace Command { bool addDependency(); bool ftp(); bool watch(); + bool clean(); public: std::shared_ptr ctx; bool parse(); diff --git a/src/Command/CommandClean.cpp b/src/Command/CommandClean.cpp new file mode 100644 index 0000000..1539177 --- /dev/null +++ b/src/Command/CommandClean.cpp @@ -0,0 +1,14 @@ +#include "Command.hpp" +#include + + +namespace Command{ + bool Interface::clean(){ + std::cout << "Cleaning: " << std::endl; + std::cout << ctx->project_path / "build/*" << std::endl; + for(auto& p: std::filesystem::directory_iterator(ctx->project_path / "build")){ + std::cout << p.path() << std::endl; + } + return true; + } +} diff --git a/src/Command/CommandGeneral.cpp b/src/Command/CommandGeneral.cpp index 6cb8871..f517a93 100644 --- a/src/Command/CommandGeneral.cpp +++ b/src/Command/CommandGeneral.cpp @@ -8,11 +8,9 @@ namespace Command { bool Interface::LoadPackageToml() { try { std::string file_name = "config.toml"; - #ifdef DEBUG - file_name = "build/config.toml"; - std::cout << "Loading config.toml from " << ctx->project_path / file_name - << std::endl; - #endif + + + auto data = toml::parse_file((ctx->project_path / file_name).string()); ctx->project_name = data["project"]["project_name"].value_or(""); for (auto &author : *data["project"]["authors"].as_array()) { diff --git a/src/Command/CommandInit.cpp b/src/Command/CommandInit.cpp index 18026d0..7ee2dc9 100644 --- a/src/Command/CommandInit.cpp +++ b/src/Command/CommandInit.cpp @@ -30,9 +30,6 @@ bool createHelloWorldCpp(std::shared_ptr ctx) { std::ofstream file; std::string file_name = ctx->project_path / "src/main.cpp"; std::cout << file_name << std::endl; - #ifdef DEBUG - file_name = "build/src/main.cpp"; - #endif file.open(ctx->project_path / file_name); file << "#include \n" "int main(){\n" @@ -49,9 +46,6 @@ bool createHelloWorldC(std::shared_ptr ctx) { #endif std::ofstream file; std::string file_name = "src/main.c"; - #ifdef DEBUG - file_name = "build/src/main.c"; - #endif file.open(ctx->project_path / file_name); file << "#include \n" "int main(){\n" @@ -101,9 +95,6 @@ bool defaultTomlCpp(std::shared_ptr ctx) { std::ofstream file; std::string file_name = "config.toml"; - #ifdef DEBUG - file_name = "build/config.toml"; - #endif file.open(ctx->project_path / file_name); file << table; @@ -117,7 +108,6 @@ bool Interface::init() { std::string file_name = "config.toml"; std::string new_project_name = ""; #ifdef DEBUG - file_name = "build/config.toml"; new_project_name = "DEBUG"; #else new_project_name = Utils::getFolderName(); diff --git a/src/Command/Interface.cpp b/src/Command/Interface.cpp index 4c7be46..b39bbb8 100644 --- a/src/Command/Interface.cpp +++ b/src/Command/Interface.cpp @@ -37,12 +37,21 @@ namespace Command { // this->help(); // } +#ifdef DEBUG + ctx->project_path = std::filesystem::current_path() / "build"; +#else + ctx->project_path = std::filesystem::current_path(); +#endif std::string command = this->args->operator[]("command").as(); #ifdef DEBUG std::cout << "DEBUG MODE ENABLED\n"; #endif + if(command != "init"){ + this->LoadPackageToml(); + } + using namespace cxxopts; if (command == "init"){ @@ -50,7 +59,6 @@ namespace Command { this->init(); } else if (command == "run"){ - this->LoadPackageToml(); this->run(); } else if (command == "help"){ @@ -62,24 +70,24 @@ namespace Command { } else if (command == "add"){ OptionsInit::Add(this); - this->LoadPackageToml(); this->add(); } else if (command == "remove"){ OptionsInit::Add(this); - this->LoadPackageToml(); this->remove(); } else if (command == "watch"){ OptionsInit::Watch(this); - this->LoadPackageToml(); this->watch(); } else if (command == "update"){ OptionsInit::Update(this); this->update(); } + else if (command == "clean"){ + this->clean(); + } else{ std::cout << "Invalid command try one of these" << ENDL; this->help(); diff --git a/src/Generators/CMakeGenerator.cpp b/src/Generators/CMakeGenerator.cpp index 38fdc98..d26c7b1 100644 --- a/src/Generators/CMakeGenerator.cpp +++ b/src/Generators/CMakeGenerator.cpp @@ -106,9 +106,6 @@ namespace Generators::CMakeList{ std::ofstream file; std::string file_name = "CMakeLists.txt"; -#ifdef DEBUG - file_name = "build/CMakeLists.txt"; -#endif try{ remove((ctx->project_path / file_name).c_str()); }catch(...){ diff --git a/src/Generators/ConfigTomlGenerator.cpp b/src/Generators/ConfigTomlGenerator.cpp index f04e5e9..0db6b1a 100644 --- a/src/Generators/ConfigTomlGenerator.cpp +++ b/src/Generators/ConfigTomlGenerator.cpp @@ -104,11 +104,6 @@ namespace Generators::ConfigToml { std::ofstream file; std::string file_name = "config.toml"; -#ifdef DEBUG - file_name = "build/config.toml"; - std::cout << "Writing config.toml to " << ctx->project_path / file_name - << std::endl; -#endif file.open(ctx->project_path / file_name); file << table; file << '\n';