From 4d3523a34638fb6d55f5df986609196f05ea8053 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 25 Apr 2025 13:37:43 +1200 Subject: [PATCH] Tidy --- src/config.cpp | 2 +- src/dropshell-completion.bash | 23 +---------------------- src/main.cpp | 19 ++++++++++++------- src/servers.cpp | 2 +- src/service_runner.cpp | 8 +------- src/service_runner.hpp | 1 - src/{ => utils}/tableprint.cpp | 0 src/{ => utils}/tableprint.hpp | 0 src/utils/utils.cpp | 13 +++++++++++++ src/utils/utils.hpp | 14 ++++++++++++++ 10 files changed, 43 insertions(+), 39 deletions(-) rename src/{ => utils}/tableprint.cpp (100%) rename src/{ => utils}/tableprint.hpp (100%) create mode 100644 src/utils/utils.cpp create mode 100644 src/utils/utils.hpp diff --git a/src/config.cpp b/src/config.cpp index 2ae15a9..6dafcfe 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -42,7 +42,7 @@ bool config::load_config() { return false; } - std::cout << "Local config path: " << mLocalConfigPath << std::endl; + //std::cout << "Local config path: " << mLocalConfigPath << std::endl; return true; } diff --git a/src/dropshell-completion.bash b/src/dropshell-completion.bash index 4fc0981..dfbe4f1 100755 --- a/src/dropshell-completion.bash +++ b/src/dropshell-completion.bash @@ -9,6 +9,7 @@ _dropshell_completions() { # add all commands to opts local commands=($(dropshell autocomplete_list_commands)) +# echo "commands: ${commands[*]}" opts="${opts} ${commands[*]}" # If we're completing the first argument, show all commands @@ -24,29 +25,7 @@ _dropshell_completions() { COMPREPLY=() 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 COMPREPLY=() return 0 diff --git a/src/main.cpp b/src/main.cpp index 6809cb5..a1abf7f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "servers.hpp" #include "utils/directories.hpp" #include "templates.hpp" +#include "utils/utils.hpp" #include #include @@ -22,7 +23,8 @@ void print_version() { 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 << "A tool for managing server configurations" << std::endl; std::cout << std::endl; @@ -30,18 +32,17 @@ void print_help() { 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 << std::endl; + std::cout << std::endl; std::cout << "Server commands:" << 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 << " templates List all available templates" << 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 << " install SERVER [SERVICE] Install/Update service(s)." << std::endl; - std::cout << " backup SERVER [SERVICE] Backup service(s)." << std::endl; - std::cout << " uninstall SERVER [SERVICE] Uninstall service(s)." << 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 << " COMMAND SERVER [SERVICE] Run a command on service(s)." << std::endl; + std::cout << std::endl; + std::cout << "Standard commands: install, backup, uninstall, start, stop" << std::endl; std::cout << std::endl; } @@ -170,6 +171,10 @@ int main(int argc, char* argv[]) { return 1; } + std::string lcd; + cfg->get_local_config_directory(lcd); + std::cout << "Local config path: " << lcd << std::endl; + // No arguments provided if (argc < 2) { dropshell::print_help(); diff --git a/src/servers.cpp b/src/servers.cpp index 0671df6..0097c1a 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -1,7 +1,7 @@ #include "servers.hpp" #include "server_env.hpp" #include "service_runner.hpp" -#include "tableprint.hpp" +#include "utils/tableprint.hpp" #include "utils/envmanager.hpp" #include "utils/directories.hpp" #include "services.hpp" diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 601f667..3b49ad1 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -2,9 +2,9 @@ #include "service_runner.hpp" #include "server_env.hpp" #include "templates.hpp" -#include "config.hpp" #include "services.hpp" #include "utils/directories.hpp" +#include "utils/utils.hpp" #include #include #include @@ -104,12 +104,6 @@ bool service_runner::execute_local_command(const std::string& command, const std 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() { maketitle("Installing " + m_service_info.service_name + " (" + m_service_info.template_name + ") on " + m_server_name); diff --git a/src/service_runner.hpp b/src/service_runner.hpp index 8742675..05790b4 100644 --- a/src/service_runner.hpp +++ b/src/service_runner.hpp @@ -90,7 +90,6 @@ class service_runner { bool check_remote_items_exist(const std::vector& file_paths) 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; - void maketitle(const std::string& title) const; }; } // namespace dropshell diff --git a/src/tableprint.cpp b/src/utils/tableprint.cpp similarity index 100% rename from src/tableprint.cpp rename to src/utils/tableprint.cpp diff --git a/src/tableprint.hpp b/src/utils/tableprint.hpp similarity index 100% rename from src/tableprint.hpp rename to src/utils/tableprint.hpp diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp new file mode 100644 index 0000000..8e6a901 --- /dev/null +++ b/src/utils/utils.cpp @@ -0,0 +1,13 @@ +#include "utils.hpp" +#include +#include + +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 \ No newline at end of file diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp new file mode 100644 index 0000000..d355618 --- /dev/null +++ b/src/utils/utils.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +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 \ No newline at end of file