add remove
All checks were successful
Clang-format Check / clang-format-check (push) Successful in 22s
Tests Check / test-check (push) Successful in 2m21s

This commit is contained in:
Timofey Khoruzhii 2023-06-11 09:39:34 +03:00
parent 41c8f0c633
commit 67f0ab5d19
4 changed files with 20 additions and 0 deletions

View file

@ -8,9 +8,13 @@
class Project {
public:
Project(const std::string& path, const std::string& path_to_scripts, const std::string& name);
Project(const Project&) = delete;
Project(Project&&) = default;
Project& operator=(const Project&) = delete;
Project& operator=(Project&&) = default;
const std::filesystem::path& GetPath() const;
const std::filesystem::path& GetPathToScripts() const;
const std::string& GetName() const;

View file

@ -13,6 +13,7 @@ class ProjectList {
const std::deque<Project>& GetProjects();
void AddProject(Project&&);
void RemoveProjectByName(const std::string& name);
const Project& GetProject(
const std::filesystem::path& path = std::filesystem::current_path()) const;

View file

@ -92,6 +92,9 @@ int main(int argc, char* argv[]) {
std::cout << "try open: " << project.GetName() << std::endl;
});
parser.AddRule(MakePattern({".", "remove", project.GetName().data()}),
[&projects](auto& args) { projects.RemoveProjectByName(args[3]); });
}
parser.AddRule(MakePattern({"help"}), [](auto& args) { std::cout << "It's help" << std::endl; });

View file

@ -21,6 +21,18 @@ void ProjectList::AddProject(Project&& project) {
projects_.push_back(std::move(project));
}
void ProjectList::RemoveProjectByName(const std::string& name) {
for (auto it = projects_.begin(); it < projects_.end(); ++it) {
auto& project = *it;
if (project.GetName() == name) {
projects_.erase(it);
return;
}
}
throw std::logic_error("Project not found");
}
const Project& ProjectList::GetProject(const std::filesystem::path& path) const {
size_t index = 0, prefix = 0;
for (size_t i = 0; i < projects_.size(); ++i) {