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.init(server.name, service))
{ {
if (ss.is_healthy()) if (ss.is_healthy())
serviceticks += ":tick: :tick: :cross: "; serviceticks += ":tick: ";
else else
serviceticks += ":cross: "; serviceticks += ":cross: ";
} }
@ -100,15 +100,8 @@ void show_server_details(const std::string& server_name) {
return; return;
} }
//---------------------
std::cout << "Server Configuration: " << server_name << std::endl;
std::cout << std::string(40, '-') << std::endl;
server_env env(server_dir.string()); 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 // 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; tableprint tp("Server Configuration: " + server_name, true);
std::cout << "Services: " << server_name << std::endl; tp.add_row({"Key", "Value"});
std::cout << std::string(40, '-') << std::endl; 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); std::vector<std::string> services = get_server_services(server_name);
for (const auto& service : services) { for (const auto& service : services) {
@ -154,19 +154,19 @@ void show_server_details(const std::string& server_name) {
healthy=true; healthy=true;
ports = ss.get_ports(); ports = ss.get_ports();
} }
std::cout << " " << (healthy ? green_tick : red_cross) << " " << service << ", ports: ";
std::cout << "(";
bool first = true; bool first = true;
std::string ports_str = "";
for (const auto& port : ports) { for (const auto& port : ports) {
if (!first) { if (!first) {
std::cout << ", "; ports_str += ", ";
} }
std::cout << port; ports_str += std::to_string(port);
first = false; 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 } // namespace dropshell

View File

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

View File

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