Tidy
This commit is contained in:
parent
5861c9c776
commit
b49bc0c5de
@ -35,7 +35,13 @@ install(FILES src/dropshell-completion.bash
|
|||||||
RENAME dropshell
|
RENAME dropshell
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install templates
|
# Create pre-install script to clean old templates
|
||||||
|
install(CODE "
|
||||||
|
message(STATUS \"Removing old template files...\")
|
||||||
|
execute_process(COMMAND rm -rf /opt/dropshell/templates)
|
||||||
|
")
|
||||||
|
|
||||||
|
# Install templates with pre-install script
|
||||||
install(DIRECTORY templates/
|
install(DIRECTORY templates/
|
||||||
DESTINATION /opt/dropshell/templates
|
DESTINATION /opt/dropshell/templates
|
||||||
)
|
)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
@ -58,4 +59,51 @@ std::vector<std::string> autocomplete_list_services(const std::string& server_na
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> autocomplete_list_commands() {
|
||||||
|
std::vector<std::string> commands;
|
||||||
|
std::set<std::string> unique_commands; // To ensure deduplication
|
||||||
|
|
||||||
|
// System templates directory
|
||||||
|
const std::string system_templates_dir = "/opt/dropshell/templates";
|
||||||
|
|
||||||
|
// User templates directory
|
||||||
|
std::string user_templates_dir;
|
||||||
|
if (!get_user_directory(user_templates_dir)) {
|
||||||
|
std::cerr << "Error: User directory not set" << std::endl;
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
user_templates_dir += "/usertemplates";
|
||||||
|
|
||||||
|
// Helper function to add commands from a directory
|
||||||
|
auto add_commands_from_dir = [&unique_commands](const std::string& dir_path) {
|
||||||
|
if (!fs::exists(dir_path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate through all template directories
|
||||||
|
for (const auto& template_entry : fs::directory_iterator(dir_path)) {
|
||||||
|
if (!fs::is_directory(template_entry)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for shell files in each template directory
|
||||||
|
for (const auto& file_entry : fs::directory_iterator(template_entry.path())) {
|
||||||
|
if (fs::is_regular_file(file_entry) &&
|
||||||
|
file_entry.path().extension() == ".sh" &&
|
||||||
|
file_entry.path().filename().string()[0] != '_') {
|
||||||
|
unique_commands.insert(file_entry.path().stem().string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add commands from both template locations
|
||||||
|
add_commands_from_dir(system_templates_dir);
|
||||||
|
add_commands_from_dir(user_templates_dir);
|
||||||
|
|
||||||
|
// Convert set to vector for return
|
||||||
|
commands.assign(unique_commands.begin(), unique_commands.end());
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -7,7 +7,7 @@ _dropshell_completions() {
|
|||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
# List of main commands
|
# List of main commands
|
||||||
opts="help version status servers templates autocomplete_list_servers autocomplete_list_services run install backup"
|
opts="help version status servers templates autocomplete_list_servers autocomplete_list_services autocomplete_list_commands run install backup"
|
||||||
|
|
||||||
# If we're completing the first argument, show all commands
|
# If we're completing the first argument, show all commands
|
||||||
if [[ ${COMP_CWORD} -eq 1 ]] ; then
|
if [[ ${COMP_CWORD} -eq 1 ]] ; then
|
||||||
@ -37,6 +37,11 @@ _dropshell_completions() {
|
|||||||
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
autocomplete_list_commands)
|
||||||
|
# No additional completions needed
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
run|install|backup)
|
run|install|backup)
|
||||||
# First argument after run/install/backup is server name
|
# First argument after run/install/backup is server name
|
||||||
local servers=($(dropshell autocomplete_list_servers))
|
local servers=($(dropshell autocomplete_list_servers))
|
||||||
|
@ -31,5 +31,8 @@ void show_server_details(const std::string& server_name);
|
|||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
std::vector<ServerInfo> get_configured_servers();
|
std::vector<ServerInfo> get_configured_servers();
|
||||||
|
std::vector<std::string> autocomplete_list_servers();
|
||||||
|
std::vector<std::string> autocomplete_list_services(const std::string& server_name);
|
||||||
|
std::vector<std::string> autocomplete_list_commands();
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -117,6 +117,14 @@ int main(int argc, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd == "autocomplete_list_commands") {
|
||||||
|
auto commands = dropshell::autocomplete_list_commands();
|
||||||
|
for (const auto& command : commands) {
|
||||||
|
std::cout << command << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (cmd == "install") {
|
if (cmd == "install") {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
std::cerr << "Error: install command requires server name and optionally service name" << std::endl;
|
std::cerr << "Error: install command requires server name and optionally service name" << std::endl;
|
||||||
|
@ -308,7 +308,7 @@ bool server_service::is_healthy()
|
|||||||
std::string env_path = service_dir + "/" + m_service_name + ".env";
|
std::string env_path = service_dir + "/" + m_service_name + ".env";
|
||||||
|
|
||||||
// Run status script, does not display output.
|
// Run status script, does not display output.
|
||||||
return execute_ssh_command("'cd " + script_dir + " && /bin/bash status.sh " + env_path + " > /dev/null 2>&1'","");
|
return execute_ssh_command("'cd " + script_dir + " && /bin/bash _status.sh " + env_path + " > /dev/null 2>&1'","");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string server_service::healthtick()
|
std::string server_service::healthtick()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user