This commit is contained in:
Your Name
2025-04-21 11:54:37 +12:00
parent a718f23375
commit c220fca691
4 changed files with 28 additions and 22 deletions

View File

@ -1,4 +1,5 @@
#include "dropshell.hpp"
#include "server_env.hpp"
#include <iostream>
#include <fstream>
#include <iomanip>
@ -23,31 +24,24 @@ std::vector<ServerInfo> get_configured_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;
}
for (const auto& entry : fs::directory_iterator(servers_dir)) {
if (fs::is_directory(entry)) {
fs::path env_file = entry.path() / "_server.env";
if (fs::exists(env_file)) {
std::ifstream file(env_file.string());
std::string line;
std::string address;
while (std::getline(file, line)) {
if (boost::starts_with(line, "SSH_ADDRESS=")) {
address = line.substr(12);
break;
}
}
if (!address.empty()) {
servers.push_back({
entry.path().filename().string(),
address
});
}
server_env env(env_file.string());
if (!env.is_valid()) {
std::cerr << "Error: Invalid server environment file: " << env_file.string() << std::endl;
continue;
}
servers.push_back({
entry.path().filename().string(),
env.get_SSH_HOST(),
env.get_SSH_USER(),
env.get_SSH_PORT()
});
}
}
@ -68,7 +62,7 @@ void list_servers() {
for (const auto& server : servers) {
max_name_len = std::max(max_name_len, server.name.length());
max_addr_len = std::max(max_addr_len, server.address.length());
max_addr_len = std::max(max_addr_len, server.ssh_host.length());
}
// Print header
@ -82,7 +76,7 @@ void list_servers() {
// Print server rows
for (const auto& server : servers) {
std::cout << std::left << std::setw(max_name_len) << server.name << " | "
<< std::setw(max_addr_len) << server.address << std::endl;
<< std::setw(max_addr_len) << server.ssh_host << std::endl;
}
}