autocomplete
This commit is contained in:
parent
e58c44b172
commit
9e6281c846
12
src/main.cpp
12
src/main.cpp
@ -6,6 +6,7 @@
|
|||||||
#include "utils/directories.hpp"
|
#include "utils/directories.hpp"
|
||||||
#include "templates.hpp"
|
#include "templates.hpp"
|
||||||
#include "utils/utils.hpp"
|
#include "utils/utils.hpp"
|
||||||
|
#include "utils/readmes.hpp"
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -41,7 +42,7 @@ void print_help() {
|
|||||||
std::cout << "Creation commands: (apply to the first local config directory)"<<std::endl;
|
std::cout << "Creation commands: (apply to the first local config directory)"<<std::endl;
|
||||||
std::cout << " create-template TEMPLATE" << std::endl;
|
std::cout << " create-template TEMPLATE" << std::endl;
|
||||||
std::cout << " create-server SERVER" << std::endl;
|
std::cout << " create-server SERVER" << std::endl;
|
||||||
std::cout << " create-service SERVER SERVICE" << std::endl;
|
std::cout << " create-service SERVER TEMPLATE SERVICE" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
||||||
@ -92,6 +93,8 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1; // error already reported
|
return 1; // error already reported
|
||||||
cfg->save_config();
|
cfg->save_config();
|
||||||
std::cout << "Config directory added: " << cfg->get_local_config_directories().back() << std::endl;
|
std::cout << "Config directory added: " << cfg->get_local_config_directories().back() << std::endl;
|
||||||
|
dropshell::create_readme_local_config_dir(cfg->get_local_config_directories().back());
|
||||||
|
|
||||||
if (cfg->get_local_config_directories().size() ==1)
|
if (cfg->get_local_config_directories().size() ==1)
|
||||||
std::cout << "DropShell is now initialised and you can add a server with 'dropshell create-server <server-name>'" << std::endl;
|
std::cout << "DropShell is now initialised and you can add a server with 'dropshell create-server <server-name>'" << std::endl;
|
||||||
else
|
else
|
||||||
@ -237,11 +240,12 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == "create-service") {
|
if (cmd == "create-service") {
|
||||||
if (argc < 4) {
|
if (argc < 5) {
|
||||||
std::cerr << "Error: create-service requires a server name and service name" << std::endl;
|
std::cerr << "Error: not enough arguments." << std::endl;
|
||||||
|
std::cerr << "dropshell create-service server template service" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
dropshell::create_service(argv[2], argv[3]);
|
dropshell::create_service(argv[2], argv[3], argv[4]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,18 +132,12 @@ std::vector<std::string> list_backups(const std::string &server_name, const std:
|
|||||||
return backups;
|
return backups;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool create_service(const std::string &server_name, const std::string &service_name)
|
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name)
|
||||||
{
|
{
|
||||||
if (server_name.empty() || service_name.empty())
|
if (server_name.empty() || template_name.empty() || service_name.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string service_dir = get_local_service_path(server_name, service_name);
|
std::string service_dir = get_local_service_path(server_name, service_name);
|
||||||
if (!service_dir.empty() && fs::exists(service_dir))
|
|
||||||
{
|
|
||||||
std::cerr << "Error: Service already exists: " << service_name << std::endl;
|
|
||||||
std::cerr << "Current service path: " << service_dir << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (service_dir.empty())
|
if (service_dir.empty())
|
||||||
{
|
{
|
||||||
@ -154,13 +148,20 @@ bool create_service(const std::string &server_name, const std::string &service_n
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template_info tinfo;
|
if (fs::exists(service_dir))
|
||||||
if (!get_template_info(service_name, tinfo))
|
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Template for service '" << service_name << "' not found" << std::endl;
|
std::cerr << "Error: Service already exists: " << service_name << std::endl;
|
||||||
std::cerr << "Please check the service name is correct and try again" << std::endl;
|
std::cerr << "Current service path: " << service_dir << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template_info tinfo;
|
||||||
|
if (!get_template_info(template_name, tinfo))
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl;
|
||||||
|
std::cerr << "Please check the template name is correct and try again" << std::endl;
|
||||||
std::cerr << "You can list all templates with 'dropshell templates'" << std::endl;
|
std::cerr << "You can list all templates with 'dropshell templates'" << std::endl;
|
||||||
std::cerr << "You can create a new template with 'dropshell create-template " << service_name << "'" << std::endl;
|
std::cerr << "You can create a new template with 'dropshell create-template " << template_name << "'" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ namespace dropshell {
|
|||||||
// list all backups for a given server and service
|
// list all backups for a given server and service
|
||||||
std::vector<std::string> list_backups(const std::string& server_name, const std::string& service_name);
|
std::vector<std::string> list_backups(const std::string& server_name, const std::string& service_name);
|
||||||
|
|
||||||
bool create_service(const std::string& server_name, const std::string& service_name);
|
bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name);
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,23 @@ namespace dropshell {
|
|||||||
|
|
||||||
std::string get_local_backup_path();
|
std::string get_local_backup_path();
|
||||||
|
|
||||||
|
|
||||||
|
// local config directories
|
||||||
|
// config_path
|
||||||
|
// |-- servers
|
||||||
|
// | |-- server_name
|
||||||
|
// | |-- server.env
|
||||||
|
// | |-- services
|
||||||
|
// | |-- service_name
|
||||||
|
// | |-- service.env
|
||||||
|
// | |-- (other config files for specific server&service)
|
||||||
|
// |-- templates
|
||||||
|
// | |-- template_name
|
||||||
|
// | |-- (script files)
|
||||||
|
// | |-- example
|
||||||
|
// | |-- service.env
|
||||||
|
// | |-- (other service config files)
|
||||||
|
|
||||||
int getNumConfigDirectories();
|
int getNumConfigDirectories();
|
||||||
std::string get_local_config_path(int index);
|
std::string get_local_config_path(int index);
|
||||||
std::string get_local_config_templates_path(int index);
|
std::string get_local_config_templates_path(int index);
|
||||||
@ -30,9 +47,11 @@ namespace dropshell {
|
|||||||
// |-- service name
|
// |-- service name
|
||||||
// |-- config <-- this is passed as argument to all scripts
|
// |-- config <-- this is passed as argument to all scripts
|
||||||
// |-- service.env
|
// |-- service.env
|
||||||
// |-- (user config files)
|
|
||||||
// |-- template
|
// |-- template
|
||||||
// |-- (script files)
|
// |-- (script files)
|
||||||
|
// |-- example
|
||||||
|
// |-- service.env
|
||||||
|
// |-- (other config files for specific server&service)
|
||||||
std::string get_remote_DROPSHELL_path(const std::string &server_name);
|
std::string get_remote_DROPSHELL_path(const std::string &server_name);
|
||||||
std::string get_remote_services_path(const std::string &server_name);
|
std::string get_remote_services_path(const std::string &server_name);
|
||||||
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name);
|
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name);
|
||||||
|
36
src/utils/readmes.cpp
Normal file
36
src/utils/readmes.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "readmes.hpp"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
void dropshell::create_readme_local_config_dir(const std::string &readme_path)
|
||||||
|
{
|
||||||
|
if (std::filesystem::exists(readme_path))
|
||||||
|
return; // already exists
|
||||||
|
|
||||||
|
std::ofstream readme_file(readme_path);
|
||||||
|
// use heredoc to write the readme
|
||||||
|
readme_file << R"(
|
||||||
|
|
||||||
|
use this directory to store your local config files for your servers and services.
|
||||||
|
dropshell create-server <server_name>
|
||||||
|
dropshell create-template <template_name>
|
||||||
|
dropshell create-service <server_name> <template_name> <service_name>
|
||||||
|
|
||||||
|
config_path
|
||||||
|
|-- servers
|
||||||
|
| |-- server_name
|
||||||
|
| |-- server.env
|
||||||
|
| |-- services
|
||||||
|
| |-- service_name
|
||||||
|
| |-- service.env
|
||||||
|
| |-- (other config files for specific server&service)
|
||||||
|
|-- templates
|
||||||
|
| |-- template_name
|
||||||
|
| |-- (script files)
|
||||||
|
| |-- example
|
||||||
|
| |-- service.env
|
||||||
|
| |-- (other service config files)
|
||||||
|
|
||||||
|
)" << std::endl;
|
||||||
|
readme_file.close();
|
||||||
|
}
|
12
src/utils/readmes.hpp
Normal file
12
src/utils/readmes.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef READMES_HPP
|
||||||
|
#define READMES_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace dropshell {
|
||||||
|
|
||||||
|
void create_readme_local_config_dir(const std::string &readme_path);
|
||||||
|
|
||||||
|
} // namespace dropshell
|
||||||
|
|
||||||
|
#endif
|
@ -158,4 +158,13 @@ void recursive_copy(const std::string & source, const std::string & destination)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ensure_directories_exist(std::vector<std::string> directories)
|
||||||
|
{
|
||||||
|
for (const auto& directory : directories) {
|
||||||
|
if (!std::filesystem::exists(directory)) {
|
||||||
|
std::filesystem::create_directories(directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -26,4 +26,6 @@ int str2int(const std::string & str);
|
|||||||
|
|
||||||
void recursive_copy(const std::string & source, const std::string & destination);
|
void recursive_copy(const std::string & source, const std::string & destination);
|
||||||
|
|
||||||
|
void ensure_directories_exist(std::vector<std::string> directories);
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
Loading…
x
Reference in New Issue
Block a user