.
This commit is contained in:
61
src/autocomplete.cpp
Normal file
61
src/autocomplete.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "dropshell.hpp"
|
||||
#include "init_user_directory.hpp"
|
||||
#include "config.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
std::vector<std::string> autocomplete_list_servers() {
|
||||
std::vector<std::string> servers;
|
||||
std::string user_dir;
|
||||
|
||||
if (!get_user_directory(user_dir)) {
|
||||
std::cerr << "Error: User directory not set" << std::endl;
|
||||
return servers;
|
||||
}
|
||||
|
||||
fs::path servers_dir = fs::path(user_dir) / "servers";
|
||||
if (!fs::exists(servers_dir)) {
|
||||
std::cerr << "Error: Servers directory not found" << std::endl;
|
||||
return servers;
|
||||
}
|
||||
|
||||
// List all server directories
|
||||
for (const auto& entry : fs::directory_iterator(servers_dir)) {
|
||||
if (fs::is_directory(entry)) {
|
||||
servers.push_back(entry.path().filename().string());
|
||||
}
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
||||
std::vector<std::string> autocomplete_list_services(const std::string& server_name) {
|
||||
std::vector<std::string> services;
|
||||
std::string user_dir;
|
||||
|
||||
if (!get_user_directory(user_dir)) {
|
||||
std::cerr << "Error: User directory not set" << std::endl;
|
||||
return services;
|
||||
}
|
||||
|
||||
fs::path server_dir = fs::path(user_dir) / "servers" / server_name;
|
||||
if (!fs::exists(server_dir)) {
|
||||
std::cerr << "Error: Server directory not found" << std::endl;
|
||||
return services;
|
||||
}
|
||||
|
||||
// Look for .env files in the server directory
|
||||
for (const auto& entry : fs::directory_iterator(server_dir)) {
|
||||
if (entry.path().extension() == ".env" && entry.path().filename().string() != "_server.env") {
|
||||
services.push_back(entry.path().stem().string());
|
||||
}
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user