Merge branch 'cli/remove' into cli/install-registry

This commit is contained in:
2022-12-22 12:17:14 +01:00
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include "RemoveAction.h"
#include "io/oki.h"
#include <iostream>
namespace fs = std::filesystem;
namespace cli {
RemoveAction::RemoveAction(const char *packageName) : packageName{packageName} {}
void RemoveAction::run(repository::Repository &repository) {
bool succes = fs::remove_all(OKI_PACKAGES_DIRECTORY/packageName);
if(succes){
std::cout << "The package " << this->packageName << " has been removed successfully !\n";
} else {
std::cout << "An error occured while removing the package " << this->packageName << "\n";
exit(1);
}
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "CliAction.h"
namespace cli {
/**
* Supprime un paquet.
*/
class RemoveAction : public CliAction {
private:
std::string_view packageName;
public:
explicit RemoveAction(const char *packageName);
void run(repository::Repository &repository) override;
};
}

View File

@@ -8,6 +8,7 @@
#include "ListAction.h"
#include "MakefileAction.h"
#include "PublishAction.h"
#include "RemoveAction.h"
#include "ShowAction.h"
#include "TreeAction.h"
@@ -21,6 +22,7 @@ namespace cli {
os << "list: List available packages\n";
os << "show: Show the informations of the package\n";
os << "install: Install a new package\n";
os << "remove: Remove the package\n";
os << "fetch: Fetch dependencies\n";
os << "publish: Publish a new version of the current package\n";
os << "makefile: Create a makefile\n";
@@ -44,6 +46,13 @@ namespace cli {
exit(1);
}
return std::make_unique<InstallAction>(argv[2]);
} else if (strcmp("remove", argv[1]) == 0) {
if (argc < 3) {
invalidUsage(std::cerr);
std::cerr << "Add a package name after remove.\n";
exit(1);
}
return std::make_unique<RemoveAction>(argv[2]);
} else if (strcmp("show", argv[1]) == 0) {
if (argc < 3) {
invalidUsage(std::cerr);