tidying
This commit is contained in:
parent
013176dbe5
commit
c5ed85c8e9
@ -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
|
||||||
@ -134,39 +127,46 @@ void show_server_details(const std::string& server_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------
|
//---------------------
|
||||||
// list services, and run healthcheck on each
|
// list services, and run healthcheck on each
|
||||||
std::cout << std::endl;
|
{
|
||||||
std::cout << "Services: " << server_name << std::endl;
|
tableprint tp("Services: " + server_name, false);
|
||||||
std::cout << std::string(40, '-') << std::endl;
|
tp.add_row({"Status", "Service", "Ports"});
|
||||||
|
|
||||||
std::string green_tick = "\033[32m✓\033[0m";
|
std::vector<std::string> services = get_server_services(server_name);
|
||||||
std::string red_cross = "\033[31m✗\033[0m";
|
for (const auto& service : services) {
|
||||||
|
bool healthy = false;
|
||||||
std::vector<std::string> services = get_server_services(server_name);
|
std::vector<int> ports;
|
||||||
for (const auto& service : services) {
|
server_service ss;
|
||||||
bool healthy = false;
|
if (ss.init(server_name, service))
|
||||||
std::vector<int> ports;
|
{
|
||||||
server_service ss;
|
if (ss.is_healthy())
|
||||||
if (ss.init(server_name, service))
|
healthy=true;
|
||||||
{
|
ports = ss.get_ports();
|
||||||
if (ss.is_healthy())
|
|
||||||
healthy=true;
|
|
||||||
ports = ss.get_ports();
|
|
||||||
}
|
|
||||||
std::cout << " " << (healthy ? green_tick : red_cross) << " " << service << ", ports: ";
|
|
||||||
std::cout << "(";
|
|
||||||
bool first = true;
|
|
||||||
for (const auto& port : ports) {
|
|
||||||
if (!first) {
|
|
||||||
std::cout << ", ";
|
|
||||||
}
|
}
|
||||||
std::cout << port;
|
bool first = true;
|
||||||
first = false;
|
std::string ports_str = "";
|
||||||
}
|
for (const auto& port : ports) {
|
||||||
std::cout << ")" << std::endl;
|
if (!first) {
|
||||||
}
|
ports_str += ", ";
|
||||||
|
}
|
||||||
}
|
ports_str += std::to_string(port);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
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
|
@ -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,14 +240,16 @@ void tableprint::print() {
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
// Print header separator
|
// Print header separator
|
||||||
std::cout << "├";
|
if (!mCompact) {
|
||||||
for (size_t i = 0; i < rows[0].size(); ++i) {
|
std::cout << "├";
|
||||||
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
|
for (size_t i = 0; i < rows[0].size(); ++i) {
|
||||||
std::cout << "-";
|
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
|
||||||
|
std::cout << "-";
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user