Fix segfault 🤦
This commit is contained in:
parent
65fad9e1b0
commit
4953d4988d
@ -2,6 +2,8 @@
|
|||||||
#include "servers.hpp"
|
#include "servers.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "templates.hpp"
|
#include "templates.hpp"
|
||||||
|
#include "services.hpp"
|
||||||
|
#include "servers.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -15,10 +17,15 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
|
|||||||
// std::cerr << std::endl;
|
// std::cerr << std::endl;
|
||||||
|
|
||||||
if (args.size() < 3) // dropshell autocomplete ???
|
if (args.size() < 3) // dropshell autocomplete ???
|
||||||
|
{
|
||||||
autocomplete_list_commands();
|
autocomplete_list_commands();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string cmd = args[2];
|
std::string cmd = args[2];
|
||||||
|
|
||||||
|
// std::cout<<" cmd = ["<<cmd<<"]"<<std::endl;
|
||||||
|
|
||||||
std::string noargcmds[] = {"templates","autocomplete_list_servers","autocomplete_list_services","autocomplete_list_commands"};
|
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))
|
if (std::find(std::begin(noargcmds), std::end(noargcmds), cmd) != std::end(noargcmds))
|
||||||
return;
|
return;
|
||||||
@ -54,7 +61,18 @@ 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?>
|
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.
|
return; // no more autocompletion possible - don't know what the argument is for.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +188,12 @@ void create_server(const std::string &server_name)
|
|||||||
|
|
||||||
void get_all_used_commands(std::set<std::string> &commands)
|
void get_all_used_commands(std::set<std::string> &commands)
|
||||||
{
|
{
|
||||||
std::set<std::string> template_shell_commands;
|
|
||||||
std::vector<ServerInfo> servers = get_configured_servers();
|
std::vector<ServerInfo> servers = get_configured_servers();
|
||||||
for (const auto& server : servers)
|
for (const auto& server : servers)
|
||||||
{
|
{
|
||||||
std::vector<dropshell::ServiceInfo> services = dropshell::get_server_services_info(server.name);
|
std::vector<dropshell::ServiceInfo> services = dropshell::get_server_services_info(server.name);
|
||||||
for (const auto& service : services)
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +111,9 @@ std::set<std::string> get_used_commands(const std::string &server_name, const st
|
|||||||
return commands;
|
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())
|
if (server_name.empty() || service_name.empty())
|
||||||
return backups;
|
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)) {
|
for (const auto& entry : fs::directory_iterator(backups_dir)) {
|
||||||
if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz")
|
if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz")
|
||||||
if (entry.path().filename().string().find(service_name) != std::string::npos)
|
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;
|
return backups;
|
||||||
|
@ -19,7 +19,7 @@ namespace dropshell {
|
|||||||
std::set<std::string> get_used_commands(const std::string& server_name, const std::string& service_name);
|
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
|
// 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);
|
bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name);
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user