This commit is contained in:
Your Name 2025-04-25 13:37:43 +12:00
parent 7d3209cdb2
commit 4d3523a346
10 changed files with 43 additions and 39 deletions

View File

@ -42,7 +42,7 @@ bool config::load_config() {
return false; return false;
} }
std::cout << "Local config path: " << mLocalConfigPath << std::endl; //std::cout << "Local config path: " << mLocalConfigPath << std::endl;
return true; return true;
} }

View File

@ -9,6 +9,7 @@ _dropshell_completions() {
# add all commands to opts # add all commands to opts
local commands=($(dropshell autocomplete_list_commands)) local commands=($(dropshell autocomplete_list_commands))
# echo "commands: ${commands[*]}"
opts="${opts} ${commands[*]}" opts="${opts} ${commands[*]}"
# If we're completing the first argument, show all commands # If we're completing the first argument, show all commands
@ -24,29 +25,7 @@ _dropshell_completions() {
COMPREPLY=() COMPREPLY=()
return 0 return 0
;; ;;
servers)
# Show available server names for servers command
local servers=($(dropshell autocomplete_list_servers))
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0
;;
install|backup)
# Handle completion for run/install/backup commands
if [[ ${COMP_CWORD} -eq 2 ]]; then
# Second argument is server name
local servers=($(dropshell autocomplete_list_servers))
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0
elif [[ ${COMP_CWORD} -eq 3 ]]; then
# Third argument is service name
local server_name="${COMP_WORDS[2]}"
local services=($(dropshell autocomplete_list_services "$server_name"))
COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) )
return 0
fi
;;
*) *)
# if ${prev} is not in ${commands}
if [[ ! " ${commands[*]} " =~ " ${root} " ]]; then if [[ ! " ${commands[*]} " =~ " ${root} " ]]; then
COMPREPLY=() COMPREPLY=()
return 0 return 0

View File

@ -5,6 +5,7 @@
#include "servers.hpp" #include "servers.hpp"
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "templates.hpp" #include "templates.hpp"
#include "utils/utils.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <iostream> #include <iostream>
@ -22,7 +23,8 @@ void print_version() {
void print_help() { void print_help() {
std::cout << "Usage: dropshell [OPTIONS] COMMAND [ARGS]" << std::endl; std::cout << std::endl;
maketitle("DropShell version " + VERSION);
std::cout << std::endl; std::cout << std::endl;
std::cout << "A tool for managing server configurations" << std::endl; std::cout << "A tool for managing server configurations" << std::endl;
std::cout << std::endl; std::cout << std::endl;
@ -30,18 +32,17 @@ void print_help() {
std::cout << " version Show version information" << std::endl; std::cout << " version Show version information" << std::endl;
std::cout << " init DIR Initialise the local dropshell directory (local config, backups, etc)" << std::endl; std::cout << " init DIR Initialise the local dropshell directory (local config, backups, etc)" << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << std::endl;
std::cout << "Server commands:" << std::endl; std::cout << "Server commands:" << std::endl;
std::cout << " servers Summary of all configured servers" << std::endl; std::cout << " servers Summary of all configured servers" << std::endl;
std::cout << " servers NAME Show details for specific server" << std::endl; std::cout << " servers NAME Show details for specific server" << std::endl;
std::cout << " templates List all available templates" << std::endl; std::cout << " templates List all available templates" << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << std::endl;
std::cout << "Service commands: (if no service is specified, all services for the server are affected)" << std::endl; std::cout << "Service commands: (if no service is specified, all services for the server are affected)" << std::endl;
std::cout << " install SERVER [SERVICE] Install/Update service(s)." << std::endl; std::cout << " COMMAND SERVER [SERVICE] Run a command on service(s)." << std::endl;
std::cout << " backup SERVER [SERVICE] Backup service(s)." << std::endl; std::cout << std::endl;
std::cout << " uninstall SERVER [SERVICE] Uninstall service(s)." << std::endl; std::cout << "Standard commands: install, backup, uninstall, start, stop" << std::endl;
std::cout << " start SERVER [SERVICE] Start service(s)." << std::endl;
std::cout << " stop SERVER [SERVICE] Stop service(s)." << std::endl;
std::cout << " COMMAND SERVER [SERVICE] Run a command on service(s)." << std::endl;
std::cout << std::endl; std::cout << std::endl;
} }
@ -170,6 +171,10 @@ int main(int argc, char* argv[]) {
return 1; return 1;
} }
std::string lcd;
cfg->get_local_config_directory(lcd);
std::cout << "Local config path: " << lcd << std::endl;
// No arguments provided // No arguments provided
if (argc < 2) { if (argc < 2) {
dropshell::print_help(); dropshell::print_help();

View File

@ -1,7 +1,7 @@
#include "servers.hpp" #include "servers.hpp"
#include "server_env.hpp" #include "server_env.hpp"
#include "service_runner.hpp" #include "service_runner.hpp"
#include "tableprint.hpp" #include "utils/tableprint.hpp"
#include "utils/envmanager.hpp" #include "utils/envmanager.hpp"
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "services.hpp" #include "services.hpp"

View File

@ -2,9 +2,9 @@
#include "service_runner.hpp" #include "service_runner.hpp"
#include "server_env.hpp" #include "server_env.hpp"
#include "templates.hpp" #include "templates.hpp"
#include "config.hpp"
#include "services.hpp" #include "services.hpp"
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "utils/utils.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -104,12 +104,6 @@ bool service_runner::execute_local_command(const std::string& command, const std
return okay; return okay;
} }
void service_runner::maketitle(const std::string& title) const {
std::cout << std::string(title.length() + 4, '-') << std::endl;
std::cout << "| " << title << " |" << std::endl;
std::cout << std::string(title.length() + 4, '-') << std::endl;
}
bool service_runner::install() { bool service_runner::install() {
maketitle("Installing " + m_service_info.service_name + " (" + m_service_info.template_name + ") on " + m_server_name); maketitle("Installing " + m_service_info.service_name + " (" + m_service_info.template_name + ") on " + m_server_name);

View File

@ -90,7 +90,6 @@ class service_runner {
bool check_remote_items_exist(const std::vector<std::string>& file_paths) const; bool check_remote_items_exist(const std::vector<std::string>& file_paths) const;
bool execute_ssh_command(const std::string& command, const std::string& error_msg) const; bool execute_ssh_command(const std::string& command, const std::string& error_msg) const;
bool execute_local_command(const std::string& command, const std::string& error_msg) const; bool execute_local_command(const std::string& command, const std::string& error_msg) const;
void maketitle(const std::string& title) const;
}; };
} // namespace dropshell } // namespace dropshell

13
src/utils/utils.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "utils.hpp"
#include <iostream>
#include <string>
namespace dropshell {
void maketitle(const std::string& title) {
std::cout << std::string(title.length() + 4, '-') << std::endl;
std::cout << "| " << title << " |" << std::endl;
std::cout << std::string(title.length() + 4, '-') << std::endl;
}
} // namespace dropshell

14
src/utils/utils.hpp Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <string>
namespace dropshell {
/**
* Prints a formatted title surrounded by a box of dashes.
*
* @param title The title string to display
*/
void maketitle(const std::string& title);
} // namespace dropshell