Update source/src/commands/edit.cpp
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
#include "config.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "utils/env_validator.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
#include "services.hpp"
|
||||
#include "templates.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
@@ -165,15 +168,61 @@ int edit_service_config(const std::string &server, const std::string &service)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate service.env matches template BEFORE editing (adds any missing variables)
|
||||
{
|
||||
LocalServiceInfo service_info = get_service_info(server, service);
|
||||
if (!SIvalid(service_info))
|
||||
{
|
||||
error << "Failed to get service info for " << service << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
template_info tinfo = gTemplateManager().get_template_info(service_info.template_name);
|
||||
if (!tinfo.is_set())
|
||||
{
|
||||
error << "Template not found: " << service_info.template_name << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path template_service_env = tinfo.local_template_path() / "config" / "service.env";
|
||||
std::filesystem::path template_info_env = tinfo.local_template_path() / "config" / ".template_info.env";
|
||||
|
||||
std::vector<std::string> missing_vars;
|
||||
std::vector<std::string> extra_vars;
|
||||
|
||||
if (!validate_and_fix_service_env(template_service_env.string(), config_file, missing_vars, extra_vars, template_info_env.string()))
|
||||
{
|
||||
info << "Service environment file updated to match template:" << std::endl;
|
||||
|
||||
if (!missing_vars.empty()) {
|
||||
info << " Added missing variables: ";
|
||||
for (size_t i = 0; i < missing_vars.size(); ++i) {
|
||||
info << missing_vars[i];
|
||||
if (i < missing_vars.size() - 1) info << ", ";
|
||||
}
|
||||
info << std::endl;
|
||||
}
|
||||
|
||||
if (!extra_vars.empty()) {
|
||||
info << " Commented out extra variables: ";
|
||||
for (size_t i = 0; i < extra_vars.size(); ++i) {
|
||||
info << extra_vars[i];
|
||||
if (i < extra_vars.size() - 1) info << ", ";
|
||||
}
|
||||
info << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (edit_file(config_file, true) && std::filesystem::exists(config_file))
|
||||
info << "Successfully edited service config file at " << config_file << std::endl;
|
||||
|
||||
std::string service_dir = localpath::service(server, service);
|
||||
list_directory(service_dir, "You may wish to edit the other files in " + service_dir);
|
||||
std::string service_dir = localpath::service(server, service);
|
||||
list_directory(service_dir, "You may wish to edit the other files in " + service_dir);
|
||||
|
||||
info << "Then to apply your changes, run:" << std::endl;
|
||||
info << " dropshell uninstall " + server + " " + service << std::endl;
|
||||
info << " dropshell install " + server + " " + service << std::endl;
|
||||
info << "Then to apply your changes, run:" << std::endl;
|
||||
info << " dropshell uninstall " + server + " " + service << std::endl;
|
||||
info << " dropshell install " + server + " " + service << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user