This commit is contained in:
Your Name 2025-04-21 22:49:10 +12:00
parent 013176dbe5
commit c5ed85c8e9
3 changed files with 56 additions and 53 deletions

View File

@ -65,7 +65,7 @@ void list_servers() {
if (ss.init(server.name, service))
{
if (ss.is_healthy())
serviceticks += ":tick: :tick: :cross: ";
serviceticks += ":tick: ";
else
serviceticks += ":cross: ";
}
@ -100,15 +100,8 @@ void show_server_details(const std::string& server_name) {
return;
}
//---------------------
std::cout << "Server Configuration: " << server_name << std::endl;
std::cout << std::string(40, '-') << std::endl;
server_env env(server_dir.string());
for (const auto& [key, value] : env.get_variables()) {
std::cout << key << ": " << value << std::endl;
}
//---------------------
// Check if server is reachable via SSH
@ -135,13 +128,20 @@ void show_server_details(const std::string& server_name) {
}
//---------------------
// list services, and run healthcheck on each
std::cout << std::endl;
std::cout << "Services: " << server_name << std::endl;
std::cout << std::string(40, '-') << std::endl;
{
tableprint tp("Server Configuration: " + server_name, true);
tp.add_row({"Key", "Value"});
for (const auto& [key, value] : env.get_variables()) {
tp.add_row({key, value});
}
tp.print();
}
std::string green_tick = "\033[32m✓\033[0m";
std::string red_cross = "\033[31m✗\033[0m";
//---------------------
// list services, and run healthcheck on each
{
tableprint tp("Services: " + server_name, false);
tp.add_row({"Status", "Service", "Ports"});
std::vector<std::string> services = get_server_services(server_name);
for (const auto& service : services) {
@ -154,19 +154,19 @@ void show_server_details(const std::string& server_name) {
healthy=true;
ports = ss.get_ports();
}
std::cout << " " << (healthy ? green_tick : red_cross) << " " << service << ", ports: ";
std::cout << "(";
bool first = true;
std::string ports_str = "";
for (const auto& port : ports) {
if (!first) {
std::cout << ", ";
ports_str += ", ";
}
std::cout << port;
ports_str += std::to_string(port);
first = false;
}
std::cout << ")" << std::endl;
}
}
tp.add_row({healthy ? ":tick:" : ":cross:", service, ports_str});
} // end of for (const auto& service : services)
tp.print();
} // end of list services
} // end of show_server_details
} // namespace dropshell

View File

@ -130,7 +130,7 @@ std::string width_print_left(std::string str,int width, std::string rowcolor) {
return oss.str();
}
tableprint::tableprint(const std::string title) : title(title) {
tableprint::tableprint(const std::string title, bool compact) : title(title), mCompact(compact) {
// Set locale for wide character support
std::setlocale(LC_ALL, "");
}
@ -176,11 +176,11 @@ void tableprint::print() {
}
// Debug output
std::cerr << "Column widths: ";
for (size_t width : col_widths) {
std::cerr << width << " ";
}
std::cerr << std::endl;
// std::cerr << "Column widths: ";
// for (size_t width : col_widths) {
// std::cerr << width << " ";
// }
// std::cerr << std::endl;
// Calculate total table width
size_t total_width = 0;
@ -240,6 +240,7 @@ void tableprint::print() {
std::cout << std::endl;
// Print header separator
if (!mCompact) {
std::cout << "";
for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
@ -248,6 +249,7 @@ void tableprint::print() {
if (i < rows[0].size() - 1) std::cout << "";
}
std::cout << "" << std::endl;
}
// Print rows
for (size_t row_idx = 1; row_idx < rows.size(); ++row_idx) {
@ -262,7 +264,7 @@ void tableprint::print() {
std::cout << std::endl;
// Print row separator if not the last row
if (row_idx < rows.size() - 1) {
if (row_idx < rows.size() - 1 && !mCompact) {
std::cout << "";
for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) {

View File

@ -11,7 +11,7 @@
// assumes the first row is the header.
class tableprint {
public:
tableprint(const std::string title = "");
tableprint(const std::string title = "", bool compact = false);
~tableprint();
void add_row(const std::vector<std::string>& row);
void print();
@ -19,6 +19,7 @@ class tableprint {
private:
std::vector<std::vector<std::string>> rows;
std::string title;
bool mCompact;
};
# endif