From ebb101e381056969e89f3987c1a09f84cf0de798 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 May 2025 11:45:37 +1200 Subject: [PATCH] dropshell release 2025.0518.1145 --- source/src/commands/help.cpp | 2 +- source/src/commands/install.cpp | 4 +- source/src/commands/ssh.cpp | 81 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 source/src/commands/ssh.cpp diff --git a/source/src/commands/help.cpp b/source/src/commands/help.cpp index ca34459..f3bf1cd 100644 --- a/source/src/commands/help.cpp +++ b/source/src/commands/help.cpp @@ -63,7 +63,7 @@ void show_command(const std::string& cmd) { } std::cout << " "; - print_left_aligned(cmd_info->help_usage, 30); + print_left_aligned(cmd_info->help_usage, 32); std::cout << cmd_info->help_description << std::endl; } diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index ec4da3b..041b57c 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -35,8 +35,8 @@ namespace dropshell false, // requires_install 0, // min_args (after command) 2, // max_args (after command) - "install SERVER [SERVICE|all]", - "Install/reinstall service(s). Safe/non-destructive way to update.", + "install [SERVER] [SERVICE|all]", + "Install/reinstall host, remote servers, or service(s). Safe/non-destructive way to update.", // heredoc R"( Install components on a server. This is safe to re-run (non-destructive) and used to update diff --git a/source/src/commands/ssh.cpp b/source/src/commands/ssh.cpp new file mode 100644 index 0000000..3c61438 --- /dev/null +++ b/source/src/commands/ssh.cpp @@ -0,0 +1,81 @@ +#include "command_registry.hpp" +#include "config.hpp" +#include "utils/utils.hpp" +#include "utils/directories.hpp" +#include "shared_commands.hpp" +#include "server_env_manager.hpp" +#include "services.hpp" +#include "servers.hpp" + +namespace dropshell +{ + + int ssh_handler(const CommandContext &ctx); + + static std::vector ssh_name_list = {"ssh"}; + + // Static registration + struct SSHCommandRegister + { + SSHCommandRegister() + { + CommandRegistry::instance().register_command({ssh_name_list, + ssh_handler, + shared_commands::std_autocomplete, + false, // hidden + true, // requires_config + true, // requires_install + 1, // min_args (after command) + 2, // max_args (after command) + "ssh SERVER", + "SSH into a server, or into a docker container for a service.", + R"( + + ssh SERVER SERVICE SSH into a docker container for a service. + ssh SERVER SSH into a server. + )"}); + } + } ssh_command_register; + + + + bool ssh_into_server(const std::string &server) + { + server_env_manager server_env(server); + if (!server_env.is_valid()) + { + std::cerr << "Error: Server " << server << " is not valid" << std::endl; + return false; + } + execute_ssh_command(server_env.get_SSH_INFO(), sCommand(remotepath::DROPSHELL_DIR(server), "ls --color && bash", {}), cMode::Interactive); + return true; + } + + bool ssh_into_service(const std::string &server, const std::string &service) + { + return true; + } + + int ssh_handler(const CommandContext &ctx) + { + if (ctx.args.size() < 1) + { + std::cerr << "Error: Server name is required" << std::endl; + return 1; + } + + std::string server = safearg(ctx.args, 0); + + if (ctx.args.size() < 2) + { + // ssh into the server + return ssh_into_server(server) ? 0 : 1; + } + + std::string service = safearg(ctx.args, 1); + + // ssh into the specific service. + return ssh_into_service(server, service) ? 0 : 1; + } + +} // namespace dropshell \ No newline at end of file