tidy
This commit is contained in:
parent
56184710a7
commit
3460224e29
@ -142,9 +142,7 @@ std::vector<std::string> config::get_local_server_definition_paths() {
|
||||
std::vector<std::string> paths;
|
||||
for (auto &path : server_definition_paths) {
|
||||
if (path.is_string() && !path.empty())
|
||||
{
|
||||
paths.push_back(path);
|
||||
}
|
||||
else
|
||||
std::cerr << "Warning: Invalid server definition path: " << path << std::endl;
|
||||
}
|
||||
|
@ -110,8 +110,10 @@ int main(int argc, char* argv[]) {
|
||||
ASSERT_MSG(safearg(argc,argv,1) != "assert", "Hello! Here is an assert.");
|
||||
|
||||
try {
|
||||
// silently attempt to load the config file.
|
||||
// silently attempt to load the config file and templates.
|
||||
gConfig().load_config();
|
||||
if (gConfig().is_config_set())
|
||||
gTemplateManager().load_sources();
|
||||
|
||||
if (argc < 2) {
|
||||
print_help();
|
||||
@ -155,9 +157,6 @@ int main(int argc, char* argv[]) {
|
||||
if (!gConfig().is_config_set())
|
||||
return die("Please run 'dropshell edit' to set up the dropshell configuration.");
|
||||
|
||||
// load the template sources.
|
||||
gTemplateManager().load_sources();
|
||||
|
||||
const std::vector<std::string> & server_definition_paths = gConfig().get_local_server_definition_paths();
|
||||
if (server_definition_paths.size()>1) { // only show if there are multiple.
|
||||
std::cout << "Server definition paths: ";
|
||||
@ -165,6 +164,8 @@ int main(int argc, char* argv[]) {
|
||||
std::cout << "["<< dir << "] ";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if (gTemplateManager().is_loaded() && gTemplateManager().get_source_count() > 0)
|
||||
gTemplateManager().print_sources();
|
||||
|
||||
if (cmd == "server" || cmd == "servers" || cmd == "list" || cmd == "view")
|
||||
switch (argc)
|
||||
|
@ -29,22 +29,19 @@ std::vector<LocalServiceInfo> get_server_services_info(const std::string& server
|
||||
|
||||
for (const auto& server_definition_path : local_server_definition_paths) {
|
||||
fs::path serverpath = server_definition_path + "/" + server_name;
|
||||
if (serverpath.string().empty()) {
|
||||
std::cerr << "Error: Server directory not found: " << serverpath << std::endl;
|
||||
return services;
|
||||
}
|
||||
fs::path servicepath = serverpath / "services";
|
||||
if (fs::exists(servicepath)) {
|
||||
for (const auto& entry : fs::directory_iterator(servicepath)) {
|
||||
if (fs::exists(serverpath)) // service is on that server...
|
||||
for (const auto& entry : fs::directory_iterator(serverpath)) {
|
||||
if (fs::is_directory(entry)) {
|
||||
std::string service_name = entry.path().filename().string();
|
||||
auto service = get_service_info(server_name, service_name);
|
||||
if (!service.template_name.empty()) {
|
||||
std::string dirname = entry.path().filename().string();
|
||||
if (dirname.empty() || dirname[0] == '.' || dirname[0] == '_')
|
||||
continue;
|
||||
auto service = get_service_info(server_name, dirname);
|
||||
if (!service.local_service_path.empty())
|
||||
services.push_back(service);
|
||||
}
|
||||
else
|
||||
std::cerr << "Warning: Failed to get service info for " << dirname << " on server " << server_name << std::endl;
|
||||
}
|
||||
}
|
||||
} // end of for (int i = 0; i < getNumConfigDirectories(); i++)
|
||||
} // end of for
|
||||
}
|
||||
|
||||
return services;
|
||||
|
@ -16,6 +16,7 @@ namespace dropshell {
|
||||
};
|
||||
|
||||
std::vector<LocalServiceInfo> get_server_services_info(const std::string& server_name);
|
||||
|
||||
LocalServiceInfo get_service_info(const std::string& server_name, const std::string& service_name);
|
||||
std::set<std::string> get_used_commands(const std::string& server_name, const std::string& service_name);
|
||||
|
||||
|
@ -38,7 +38,8 @@
|
||||
}
|
||||
|
||||
bool template_source_local::has_template(const std::string& template_name) {
|
||||
return std::filesystem::exists(mLocalPath / template_name);
|
||||
std::filesystem::path path = mLocalPath / template_name;
|
||||
return (std::filesystem::exists(path));
|
||||
}
|
||||
|
||||
bool template_source_local::template_command_exists(const std::string& template_name, const std::string& command) {
|
||||
@ -104,6 +105,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void template_manager::list_templates() const {
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
auto templates = get_template_list();
|
||||
|
||||
if (templates.empty()) {
|
||||
@ -126,6 +128,7 @@
|
||||
|
||||
std::set<std::string> template_manager::get_template_list() const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
std::set<std::string> templates;
|
||||
for (const auto& source : mSources) {
|
||||
auto source_templates = source->get_template_list();
|
||||
@ -136,6 +139,7 @@
|
||||
|
||||
bool template_manager::has_template(const std::string &template_name) const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
template_source_interface* source = get_source(template_name);
|
||||
if (!source)
|
||||
return false;
|
||||
@ -144,15 +148,18 @@
|
||||
|
||||
template_info template_manager::get_template_info(const std::string &template_name) const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
template_source_interface* source = get_source(template_name);
|
||||
if (!source) {
|
||||
return template_info();
|
||||
}
|
||||
return source->get_template_info(template_name);
|
||||
}
|
||||
if (source)
|
||||
return source->get_template_info(template_name);
|
||||
|
||||
// fail
|
||||
return template_info();
|
||||
}
|
||||
|
||||
bool template_manager::template_command_exists(const std::string &template_name, const std::string &command) const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
template_source_interface* source = get_source(template_name);
|
||||
if (!source) {
|
||||
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl;
|
||||
@ -233,9 +240,7 @@
|
||||
readme_file.close();
|
||||
}
|
||||
std::cout << std::string(60, '-') << std::endl;
|
||||
} else {
|
||||
std::cout << "No README.txt file found in the template." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Template '" << template_name << "' created at " << new_template_path << std::endl;
|
||||
@ -248,33 +253,31 @@
|
||||
ASSERT(gConfig().is_config_set());
|
||||
ASSERT(!mLoaded);
|
||||
auto local_template_paths = gConfig().get_template_local_paths();
|
||||
if (local_template_paths.empty()) {
|
||||
std::cerr << "Error: No local template paths found" << std::endl;
|
||||
std::cerr << "Run 'dropshell edit' to add one to the DropShell config" << std::endl;
|
||||
if (local_template_paths.empty())
|
||||
return;
|
||||
}
|
||||
for (const auto& path : local_template_paths) {
|
||||
for (const auto& path : local_template_paths)
|
||||
mSources.push_back(std::make_unique<template_source_local>(path));
|
||||
}
|
||||
|
||||
auto registry_urls = gConfig().get_template_registry_urls();
|
||||
for (const auto& url : registry_urls) {
|
||||
for (const auto& url : registry_urls)
|
||||
mSources.push_back(std::make_unique<template_source_registry>(url));
|
||||
}
|
||||
|
||||
mLoaded = true;
|
||||
}
|
||||
|
||||
void template_manager::print_sources() const
|
||||
{
|
||||
std::cout << "Template sources: ";
|
||||
for (const auto& source : mSources) {
|
||||
std::cout << "[" << source->get_description() << "] ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
mLoaded = true;
|
||||
}
|
||||
|
||||
bool template_manager::required_file(std::string path, std::string template_name)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
std::cerr << "Error: " << path << " file not found in template " << template_name << std::endl;
|
||||
std::cerr << "Error: " << path << " file not found in template - REQUIRED." << template_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -282,6 +285,7 @@
|
||||
|
||||
template_source_interface *template_manager::get_source(const std::string &template_name) const
|
||||
{
|
||||
ASSERT(mLoaded && mSources.size() > 0);
|
||||
for (const auto& source : mSources) {
|
||||
if (source->has_template(template_name)) {
|
||||
return source.get();
|
||||
|
@ -90,6 +90,10 @@ class template_manager {
|
||||
void list_templates() const;
|
||||
|
||||
void load_sources();
|
||||
void print_sources() const;
|
||||
|
||||
bool is_loaded() const { return mLoaded; }
|
||||
int get_source_count() const { return mSources.size(); }
|
||||
|
||||
private:
|
||||
static bool required_file(std::string path, std::string template_name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user