tidy
This commit is contained in:
49
src/main.cpp
49
src/main.cpp
@ -128,7 +128,7 @@ int main(int argc, char* argv[]) {
|
||||
commands.insert("init");
|
||||
if (cfg->is_config_set())
|
||||
commands.merge(std::set<std::string>{
|
||||
"servers","templates","install","uninstall","backup"
|
||||
"servers","templates"
|
||||
});
|
||||
|
||||
for (const auto& command : commands) {
|
||||
@ -188,52 +188,7 @@ int main(int argc, char* argv[]) {
|
||||
dropshell::list_templates();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmd == "install" || cmd == "uninstall") {
|
||||
std::string server_name;
|
||||
std::vector<dropshell::ServiceInfo> servicelist;
|
||||
if (!parseargs(safearg(argc, argv, 2), safearg(argc, argv, 3), server_name, servicelist)) {
|
||||
std::cerr << "Error: " << cmd << " command requires server name and optionally service name" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
for (const auto& service_info : servicelist) {
|
||||
dropshell::service_runner service;
|
||||
if (!service.init(server_name, service_info.service_name)) {
|
||||
std::cerr << "Error: Failed to initialize service" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
bool success = ((cmd=="install") ? service.install() : service.uninstall());
|
||||
if (!success) {
|
||||
std::cerr << "Error: Failed to " << cmd << " service" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmd == "backup") {
|
||||
std::string server_name;
|
||||
std::vector<dropshell::ServiceInfo> servicelist;
|
||||
if (!parseargs(safearg(argc, argv, 2), safearg(argc, argv, 3), server_name, servicelist)) {
|
||||
std::cerr << "Error: backup command requires server name and optionally service name" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (const auto& service_info : servicelist) {
|
||||
dropshell::service_runner service;
|
||||
if (!service.init(server_name, service_info.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// handle running a command.
|
||||
for (const auto& command : commands) {
|
||||
if (cmd == command) {
|
||||
|
Reference in New Issue
Block a user