diff --git a/src/config.cpp b/src/config.cpp index 8f02de7..2ae15a9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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; } diff --git a/src/main.cpp b/src/main.cpp index a9fd657..ba34fba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "servers.hpp" #include "utils/directories.hpp" #include "config.hpp" +#include #include #include @@ -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{ - "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{ "servers","templates","install","backup" diff --git a/src/servers.cpp b/src/servers.cpp index ea07271..d25ca2f 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -70,6 +70,7 @@ void list_servers() { else serviceticks += ":cross: "; } + else std::cout<<"Error: Failed to initialise service runner for server: ["< ports = ss.get_ports(); ports_used.insert(ports_used.end(), ports.begin(), ports.end()); } diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 67e5bb4..ce10f40 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -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_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(); } diff --git a/src/services.cpp b/src/services.cpp index 162e27d..93f02ee 100644 --- a/src/services.cpp +++ b/src/services.cpp @@ -12,6 +12,9 @@ namespace dropshell { std::vector get_server_services_info(const std::string& server_name) { std::vector 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 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 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()) {