Working
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 27s

This commit is contained in:
Your Name
2025-05-11 13:04:12 +12:00
parent 46396369d7
commit 62191cceed
7 changed files with 134 additions and 43 deletions

View File

@ -140,18 +140,18 @@ int edit_service_config(const std::string &server, const std::string &service)
// ------------------------------------------------------------------------------------------------
int edit_handler(const CommandContext& ctx) {
// edit dropshell config
if (ctx.args.size() < 3)
if (ctx.args.size() < 1)
return edit_config();
// edit server config
if (ctx.args.size() < 4) {
edit_server(safearg(ctx.args,2));
if (ctx.args.size() < 2) {
edit_server(safearg(ctx.args,0));
return 0;
}
// edit service config
if (ctx.args.size() < 5) {
edit_service_config(safearg(ctx.args,2), safearg(ctx.args,3));
if (ctx.args.size() < 3) {
edit_service_config(safearg(ctx.args,0), safearg(ctx.args,1));
return 0;
}

107
src/commands/list.cpp Normal file
View File

@ -0,0 +1,107 @@
#include "command_registry.hpp"
#include "config.hpp"
#include "utils/utils.hpp"
#include "service_runner.hpp"
#include "utils/directories.hpp"
#include "standard_autocomplete.hpp"
#include "servers.hpp"
#include "tableprint.hpp"
#include "transwarp.hpp"
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
namespace dropshell {
void list_autocomplete(const CommandContext& ctx);
int list_handler(const CommandContext& ctx);
static std::vector<std::string> list_name_list={"list","ls","info","-l"};
// Static registration
struct ListCommandRegister {
ListCommandRegister() {
CommandRegistry::instance().register_command({
list_name_list,
list_handler,
list_autocomplete,
false, // hidden
false, // requires_config
0, // min_args (after command)
2, // max_args (after command)
"list [SERVER] [SERVICE]",
"List dropshell, server or service configuration"
});
}
} list_command_register;
// ------------------------------------------------------------------------------------------------
// list command autocomplete
// ------------------------------------------------------------------------------------------------
void list_autocomplete(const CommandContext& ctx) {
std_autocomplete(list_name_list, ctx);
}
// ------------------------------------------------------------------------------------------------
// list command handler
// ------------------------------------------------------------------------------------------------
int list_handler(const CommandContext& ctx) {
if (ctx.args.size() == 0) {
list_servers();
return 0;
}
std::cout << "List handler called with " << ctx.args.size() << " args\n";
return 0;
}
// https://github.com/bloomen/transwarp?tab=readme-ov-file#range-functions
void list_servers() {
auto servers = get_configured_servers();
if (servers.empty()) {
std::cout << "No servers found" << std::endl;
std::cout << "Please run 'dropshell edit' to set up dropshell." << std::endl;
std::cout << "Then run 'dropshell create-server' to create a server." << std::endl;
return;
}
tableprint tp("All DropShell Servers");
tp.add_row({"Name", "User", "Address", "Health", "Ports"});
std::cout << "Checking "<<servers.size() << " servers: " << std::flush;
int checked = 0;
transwarp::parallel exec{servers.size()};
auto task = transwarp::for_each(exec, servers.begin(), servers.end(), [&](const ServerInfo& server) {
std::map<std::string, ServiceStatus> status = service_runner::get_all_services_status(server.name);
std::set<int> ports_used;
std::string serviceticks = "";
for (const auto& [service_name, service_status] : status) {
ports_used.insert(service_status.ports.begin(), service_status.ports.end());
serviceticks += service_runner::HealthStatus2String(service_status.health) + " ";
}
std::string ports_used_str = "";
for (const auto& port : ports_used)
ports_used_str += std::to_string(port) + " ";
tp.add_row({server.name, server.ssh_user, server.ssh_host, serviceticks, ports_used_str});
++checked;
// print out a tick character for each server checked.
std::cout << checked << "" << std::flush;
});
task->wait();
std::cout << std::endl << std::endl;
tp.print();
}
} // namespace dropshell