Refactor now mostly working
This commit is contained in:
parent
dbbb0af459
commit
94f2236a7c
@ -41,6 +41,8 @@ bool config::load_config() {
|
||||
std::cerr << "Warning: User directory not set in config" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Local config path: " << mLocalConfigPath << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
14
src/main.cpp
14
src/main.cpp
@ -5,6 +5,7 @@
|
||||
#include "servers.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "config.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -67,6 +68,13 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// don't load old config if we're initializing
|
||||
if (cmd == "init") {
|
||||
std::string lcd;
|
||||
if (boost::filesystem::exists(dropshell::get_local_dropshell_config_path())) {
|
||||
std::cerr << "DropShell is already initialised in " << dropshell::get_local_dropshell_config_path() << std::endl;
|
||||
std::cerr << "Please manually delete this old config file and re-run the init command." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
std::cerr << "Error: init command requires a directory argument" << std::endl;
|
||||
return 1;
|
||||
@ -75,7 +83,7 @@ int main(int argc, char* argv[]) {
|
||||
cfg->init_local_config_directory(argv[2]);
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
std::cerr << "Error in init: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -105,8 +113,10 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (cmd == "autocomplete_list_commands") {
|
||||
commands.merge(std::set<std::string>{
|
||||
"help","version","init"
|
||||
"help","version"
|
||||
});
|
||||
if (!boost::filesystem::exists(dropshell::get_local_dropshell_config_path()))
|
||||
commands.insert("init");
|
||||
if (cfg->is_config_set())
|
||||
commands.merge(std::set<std::string>{
|
||||
"servers","templates","install","backup"
|
||||
|
@ -70,6 +70,7 @@ void list_servers() {
|
||||
else
|
||||
serviceticks += ":cross: ";
|
||||
}
|
||||
else std::cout<<"Error: Failed to initialise service runner for server: ["<<server.name<<"] and service: ["<<service.service_name<<"]"<<std::endl;
|
||||
std::vector<int> ports = ss.get_ports();
|
||||
ports_used.insert(ports_used.end(), ports.begin(), ports.end());
|
||||
}
|
||||
|
@ -21,11 +21,15 @@ namespace dropshell {
|
||||
service_runner::service_runner() : m_server_name(""), m_server_env(nullptr) {}
|
||||
|
||||
bool service_runner::init(const std::string& server_name, const std::string& service_name) {
|
||||
if (server_name.empty() || service_name.empty())
|
||||
return false;
|
||||
|
||||
// Initialize server environment
|
||||
try {
|
||||
m_server_env = std::make_unique<server_env>(server_name);
|
||||
if (!m_server_env->is_valid()) {
|
||||
std::cerr << "Error: Invalid server environment" << std::endl;
|
||||
m_server_env.reset();
|
||||
return false;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
@ -33,14 +37,14 @@ bool service_runner::init(const std::string& server_name, const std::string& ser
|
||||
return false;
|
||||
}
|
||||
|
||||
m_server_name = server_name;
|
||||
m_service_info = get_service_info(server_name, service_name);
|
||||
|
||||
mRemote_service_path = get_remote_service_path(m_server_name, m_service_info.service_name);
|
||||
mRemote_service_config_path = get_remote_service_config_path(m_server_name, m_service_info.service_name);
|
||||
mRemote_service_template_path = get_remote_service_template_path(m_server_name, m_service_info.service_name);
|
||||
mRemote_service_env_file = get_remote_service_env_file(m_server_name, m_service_info.service_name);
|
||||
|
||||
|
||||
m_server_name = server_name;
|
||||
m_service_info = get_service_info(server_name, service_name);
|
||||
return !m_service_info.path.empty();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,9 @@ namespace dropshell {
|
||||
std::vector<ServiceInfo> get_server_services_info(const std::string& server_name) {
|
||||
std::vector<ServiceInfo> services;
|
||||
|
||||
if (server_name.empty())
|
||||
return services;
|
||||
|
||||
std::string serverpath = get_local_config_servers_path();
|
||||
if (serverpath.empty()) {
|
||||
std::cerr << "Error: Server directory not found: " << serverpath << std::endl;
|
||||
@ -26,6 +29,7 @@ std::vector<ServiceInfo> get_server_services_info(const std::string& server_name
|
||||
if (fs::is_directory(entry)) {
|
||||
ServiceInfo service = get_service_info(server_name, entry.path().filename().string());
|
||||
if (!service.template_name.empty()) {
|
||||
// std::cout << "Service: " << service.service_name << " found in " << server_dir.string() << ", with template: " << service.template_name << std::endl;
|
||||
services.push_back(service);
|
||||
}
|
||||
}
|
||||
@ -37,11 +41,18 @@ std::vector<ServiceInfo> get_server_services_info(const std::string& server_name
|
||||
|
||||
ServiceInfo get_service_info(const std::string &server_name, const std::string &service_name)
|
||||
{
|
||||
if (server_name.empty() || service_name.empty())
|
||||
return ServiceInfo();
|
||||
|
||||
std::string service_dir = get_local_service_path(server_name, service_name);
|
||||
if (service_dir.empty())
|
||||
return ServiceInfo();
|
||||
|
||||
ServiceInfo service;
|
||||
service.path = service_dir;
|
||||
service.service_name = service_name;
|
||||
|
||||
// now set the template name and path.
|
||||
std::string local_service_env_path = get_local_service_env_path(server_name, service_name);
|
||||
envmanager env(local_service_env_path);
|
||||
if (!env.load()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user