Skip to content

Commit

Permalink
refactored some stuff and added clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Nov 3, 2023
1 parent e77f2dc commit 8631053
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/Command/Command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace Command {
bool addDependency();
bool ftp();
bool watch();
bool clean();
public:
std::shared_ptr<Context> ctx;
bool parse();
Expand Down
14 changes: 14 additions & 0 deletions src/Command/CommandClean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Command.hpp"
#include <filesystem>


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;
}
}
8 changes: 3 additions & 5 deletions src/Command/CommandGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 0 additions & 10 deletions src/Command/CommandInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ bool createHelloWorldCpp(std::shared_ptr<Context> 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 <iostream>\n"
"int main(){\n"
Expand All @@ -49,9 +46,6 @@ bool createHelloWorldC(std::shared_ptr<Context> 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 <stdio.h>\n"
"int main(){\n"
Expand Down Expand Up @@ -101,9 +95,6 @@ bool defaultTomlCpp(std::shared_ptr<Context> 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;
Expand All @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions src/Command/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,28 @@ 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<std::string>();

#ifdef DEBUG
std::cout << "DEBUG MODE ENABLED\n";
#endif
if(command != "init"){
this->LoadPackageToml();
}


using namespace cxxopts;
if (command == "init"){
OptionsInit::Init(this);
this->init();
}
else if (command == "run"){
this->LoadPackageToml();
this->run();
}
else if (command == "help"){
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/Generators/CMakeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(...){
Expand Down
5 changes: 0 additions & 5 deletions src/Generators/ConfigTomlGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 8631053

Please sign in to comment.