autocomplete

This commit is contained in:
Your Name
2025-04-26 08:34:02 +12:00
parent e58c44b172
commit 9e6281c846
8 changed files with 102 additions and 19 deletions

View File

@@ -11,6 +11,23 @@ namespace dropshell {
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();
std::string get_local_config_path(int index);
std::string get_local_config_templates_path(int index);
@@ -30,9 +47,11 @@ namespace dropshell {
// |-- service name
// |-- config <-- this is passed as argument to all scripts
// |-- service.env
// |-- (user config files)
// |-- template
// |-- (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_services_path(const std::string &server_name);
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name);

36
src/utils/readmes.cpp Normal file
View 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
View 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

View File

@@ -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

View File

@@ -26,4 +26,6 @@ int str2int(const std::string & str);
void recursive_copy(const std::string & source, const std::string & destination);
void ensure_directories_exist(std::vector<std::string> directories);
} // namespace dropshell