add remove
This commit is contained in:
parent
41c8f0c633
commit
67f0ab5d19
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; });
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue