Fix segfault 🤦

This commit is contained in:
Your Name 2025-04-26 18:05:18 +12:00
parent 65fad9e1b0
commit 4953d4988d
4 changed files with 24 additions and 7 deletions

View File

@ -2,6 +2,8 @@
#include "servers.hpp"
#include "config.hpp"
#include "templates.hpp"
#include "services.hpp"
#include "servers.hpp"
#include <algorithm>
#include <iostream>
@ -15,10 +17,15 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
// std::cerr << std::endl;
if (args.size() < 3) // dropshell autocomplete ???
{
autocomplete_list_commands();
return;
}
std::string cmd = args[2];
// std::cout<<" cmd = ["<<cmd<<"]"<<std::endl;
std::string noargcmds[] = {"templates","autocomplete_list_servers","autocomplete_list_services","autocomplete_list_commands"};
if (std::find(std::begin(noargcmds), std::end(noargcmds), cmd) != std::end(noargcmds))
return;
@ -55,6 +62,17 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
if (args.size()==5) // we have the command and the server and the service. dropshell autocomplete command server service_name <command?>
{
std::string service_name = args[4];
if (cmd=="restore")
{
std::set<std::string> backups;
std::vector<dropshell::ServerInfo> servers = dropshell::get_configured_servers();
for (auto server : servers)
backups.merge(dropshell::list_backups(server.name, service_name));
for (auto backup : backups)
std::cout << backup << std::endl;
}
return; // no more autocompletion possible - don't know what the argument is for.
}

View File

@ -188,13 +188,12 @@ void create_server(const std::string &server_name)
void get_all_used_commands(std::set<std::string> &commands)
{
std::set<std::string> template_shell_commands;
std::vector<ServerInfo> servers = get_configured_servers();
for (const auto& server : servers)
{
std::vector<dropshell::ServiceInfo> services = dropshell::get_server_services_info(server.name);
for (const auto& service : services)
template_shell_commands.merge(dropshell::get_used_commands(server.name, service.service_name));
commands.merge(dropshell::get_used_commands(server.name, service.service_name));
}
}

View File

@ -111,9 +111,9 @@ std::set<std::string> get_used_commands(const std::string &server_name, const st
return commands;
}
std::vector<std::string> list_backups(const std::string &server_name, const std::string &service_name)
std::set<std::string> list_backups(const std::string &server_name, const std::string &service_name)
{
std::vector<std::string> backups;
std::set<std::string> backups;
if (server_name.empty() || service_name.empty())
return backups;
@ -126,7 +126,7 @@ std::vector<std::string> list_backups(const std::string &server_name, const std:
for (const auto& entry : fs::directory_iterator(backups_dir)) {
if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz")
if (entry.path().filename().string().find(service_name) != std::string::npos)
backups.push_back(entry.path().filename().string());
backups.insert(entry.path().filename().string());
}
}
return backups;

View File

@ -19,7 +19,7 @@ namespace dropshell {
std::set<std::string> get_used_commands(const std::string& server_name, const std::string& service_name);
// list all backups for a given server and service
std::vector<std::string> list_backups(const std::string& server_name, const std::string& service_name);
std::set<std::string> list_backups(const std::string& server_name, const std::string& service_name);
bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name);
} // namespace dropshell