This commit is contained in:
Your Name
2025-04-21 16:12:06 +12:00
parent 7d1db266b0
commit bd27109a2b
5 changed files with 64 additions and 65 deletions

View File

@ -18,14 +18,14 @@ void print_help() {
std::cout << "Commands:" << std::endl;
std::cout << " help Show this help message" << std::endl;
std::cout << " version Show version information" << std::endl;
std::cout << " init DIR Initialize the user directory for server configurations" << std::endl;
std::cout << " init DIR Set the local directory for all server configs and backups" << std::endl;
std::cout << std::endl;
std::cout << " servers List configured servers" << std::endl;
std::cout << " servers Summary of all configured servers" << std::endl;
std::cout << " servers NAME Show details for specific server" << std::endl;
std::cout << " templates List available templates" << std::endl;
std::cout << " templates List all available templates" << std::endl;
std::cout << std::endl;
std::cout << " install SERVER SERVICE (Re)install a service on a server." << std::endl;
std::cout << " backup SERVER SERVICE Backup a service on a server." << std::endl;
std::cout << " install SERVER [SERVICE] (Re)install a specific service on a server." << std::endl;
std::cout << " backup SERVER [SERVICE] Backup a specific service on a server." << std::endl;
std::cout << " run SERVER SERVICE COMMAND Run a command on a specific service" << std::endl;
std::cout << std::endl;
std::cout << "Examples:" << std::endl;
@ -118,22 +118,33 @@ int main(int argc, char* argv[]) {
}
if (cmd == "install") {
if (argc < 4) {
std::cerr << "Error: install command requires server name and service name" << std::endl;
if (argc < 3) {
std::cerr << "Error: install command requires server name and optionally service name" << std::endl;
return 1;
}
std::string server_name = argv[2];
std::string service_name = argv[3];
dropshell::server_service service;
if (!service.init(server_name, service_name)) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.install()) {
std::cerr << "Error: Failed to install service" << std::endl;
return 1;
std::vector<std::string> servicelist;
if (argc <= 3) {
servicelist = dropshell::get_server_services(server_name);
if (servicelist.empty()) {
std::cerr << "Error: No services found for server " << server_name << std::endl;
return 1;
}
} else
servicelist.push_back(argv[3]);
for (const auto& service_name : servicelist) {
dropshell::server_service service;
if (!service.init(server_name, service_name)) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.install()) {
std::cerr << "Error: Failed to install service" << std::endl;
return 1;
}
}
return 0;
}
@ -161,22 +172,32 @@ int main(int argc, char* argv[]) {
}
if (cmd == "backup") {
if (argc < 4) {
std::cerr << "Error: backup command requires server name and service name" << std::endl;
if (argc < 3) {
std::cerr << "Error: backup command requires server name and optionally service name" << std::endl;
return 1;
}
std::string server_name = argv[2];
std::string service_name = argv[3];
dropshell::server_service service;
if (!service.init(server_name, service_name)) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.backup()) {
std::cerr << "Backup failed." << std::endl;
return 1;
std::vector<std::string> servicelist;
if (argc <= 3) {
servicelist = dropshell::get_server_services(server_name);
if (servicelist.empty()) {
std::cerr << "Error: No services found for server " << server_name << std::endl;
return 1;
}
} else
servicelist.push_back(argv[3]);
for (const auto& service_name : servicelist) {
dropshell::server_service service;
if (!service.init(server_name, service_name)) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.backup()) {
std::cerr << "Backup failed." << std::endl;
return 1;
}
}
return 0;
}