Skip to content

Commit

Permalink
added remove template command
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Feb 9, 2024
1 parent aca32b8 commit feb1d92
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 51 deletions.
5 changes: 5 additions & 0 deletions include/Frate/Command/Template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "Frate/Interface.hpp"
#include <memory>
namespace Frate::Command::Template{
bool remove(std::shared_ptr<Frate::Command::Interface> inter);
}
9 changes: 6 additions & 3 deletions include/Frate/Template/Manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ namespace Frate::Project {
* install that template
* @param git url of the template to install
*/
TemplateRenderer getLatest(std::string &git_url);
TemplateRenderer installLatest(std::string &git_url);
TemplateRenderer uninstallAll(std::string &name);
TemplateRenderer get(std::string &name,std::string &hash);
TemplateRenderer promptList();
/*
* Uninstalls a template
* @param name the name of the template to uninstall
*/
void uninstall(std::string &name);
void uninstall(std::string &name,std::string &hash);
/*
* Updates to the latest version of the template
* @param name the name of the template to update
Expand All @@ -84,8 +85,10 @@ namespace Frate::Project {

void installAll();

void deleteAll();

/*
* Creates a tempalte in a tmp path and then returns the path that rendering
* Creates a template in a tmp path and then returns the path that rendering
* is supposed to happen in
* @param override_path the path to override the template path with
* @param name the name of the template to create
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Actions/New.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Frate::Command::New {
if(inter->pro->type.empty()){
current_template = inter->templates->promptList();
}else{
current_template = inter->templates->getLatest(inter->pro->type);
current_template = inter->templates->installLatest(inter->pro->type);
}

try{
Expand Down
20 changes: 14 additions & 6 deletions src/Command/Actions/Remove.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "Frate/Command/Library.hpp"
#include "Frate/Generators.hpp"
#include "Frate/Project/Config.hpp"
#include "Frate/Utils/General.hpp"
#include <Frate/Command/Actions/Remove.hpp>
#include <Frate/Command/Author.hpp>
#include <Frate/Command/Flags.hpp>
#include <Frate/Command/Modes.hpp>
#include <Frate/Command/Package.hpp>
#include <Frate/Command/Template.hpp>

namespace Frate::Command::Remove {

Expand All @@ -19,7 +17,8 @@ namespace Frate::Command::Remove {
("m,mode","make changes to compile mode",cxxopts::value<std::string>())
("subcommand", "Subcommand to run", cxxopts::value<std::string>())
("h,help", "Print usage")
("args","Arguments to pass to subcommand",cxxopts::value<std::vector<std::string>>());
("args","Arguments to pass to subcommand",cxxopts::value<std::vector<std::string>>())
("a,all","Remove all",cxxopts::value<bool>());
// clang-format on
return inter->parse();
}
Expand All @@ -31,7 +30,8 @@ namespace Frate::Command::Remove {
}

std::vector<Handler> handlers(std::shared_ptr<Interface> inter) {
return {{
return {
{
.aliases = {"packages", "p", "package"},
.flags = {"-l,--latest", "-m,--mode", "-t,--target"},
.positional_args = {"package_name"},
Expand Down Expand Up @@ -64,7 +64,15 @@ namespace Frate::Command::Remove {
.docs = "Remove an author from the project",
.callback = &Author::remove,
.unlimited_args = true,
}};
},
{
.aliases = {"template"},
.flags = {"-a,--all"},
.positional_args = {"template_name"},
.docs = "Remove a template from the project",
.callback = &Template::remove
}
};
}

bool run(std::shared_ptr<Interface> inter) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Actions/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Frate::Command::Update {
.aliases = {"template-index", "tindex"},
.docs = "Update template index",
.callback = &TemplateIndex::update,
}
},
};
}

Expand Down
43 changes: 43 additions & 0 deletions src/Command/Template/Remove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <Frate/Command/Template.hpp>

namespace Frate::Command::Template {
bool remove(std::shared_ptr<Frate::Command::Interface> inter) {
std::string template_name;
bool all;


if (inter->args->count("args")) {
template_name = inter->args->operator[]("args").as<std::string>();
}
if (inter->args->count("all")) {
all = inter->args->operator[]("all").as<bool>();
}

Utils::info << "Removing template " << template_name << std::endl;
Utils::info << "All: " << all << std::endl;

if (all) {
try{
inter->templates->deleteAll();
return true;
} catch (std::exception &e) {
Utils::error << e.what() << std::endl;
return false;
}
} else {
if(template_name.empty()) {
Utils::error << "No template name given" << std::endl;
return false;
}
try{
inter->templates->uninstallAll(template_name);
return true;
} catch (std::exception &e) {
Utils::error << e.what() << std::endl;
return false;
}
}

return false;
}
}
Loading

0 comments on commit feb1d92

Please sign in to comment.