diff --git a/templates/dropshell-agent/shared/_allservicesstatus.sh b/agent/remote/_allservicesstatus.sh similarity index 100% rename from templates/dropshell-agent/shared/_allservicesstatus.sh rename to agent/remote/_allservicesstatus.sh diff --git a/templates/dropshell-agent/shared/_autocommands.sh b/agent/remote/_autocommands.sh similarity index 100% rename from templates/dropshell-agent/shared/_autocommands.sh rename to agent/remote/_autocommands.sh diff --git a/templates/dropshell-agent/shared/_common.sh b/agent/remote/_common.sh similarity index 100% rename from templates/dropshell-agent/shared/_common.sh rename to agent/remote/_common.sh diff --git a/templates/dropshell-agent/_nuke_other.sh b/agent/remote/_nuke_other.sh similarity index 100% rename from templates/dropshell-agent/_nuke_other.sh rename to agent/remote/_nuke_other.sh diff --git a/src/commands/command_registry.cpp b/src/commands/command_registry.cpp index b82d6ad..6798a19 100644 --- a/src/commands/command_registry.cpp +++ b/src/commands/command_registry.cpp @@ -1,5 +1,6 @@ #include "command_registry.hpp" #include "utils/utils.hpp" +#include "config.hpp" namespace dropshell { @@ -37,7 +38,13 @@ std::vector CommandRegistry::list_primary_commands(bool include_hid for (const auto& cmd : all_commands_) { if (!cmd->hidden || include_hidden) { if (cmd->names.size() > 0) - out.insert(cmd->names[0]); + { + if (cmd->requires_config && !gConfig().is_config_set()) + continue; + if (cmd->requires_install && !gConfig().is_agent_installed()) + continue; + out.insert(cmd->names[0]); + } } } return std::vector(out.begin(), out.end()); diff --git a/src/commands/command_registry.hpp b/src/commands/command_registry.hpp index a59cfe9..114e098 100644 --- a/src/commands/command_registry.hpp +++ b/src/commands/command_registry.hpp @@ -24,7 +24,8 @@ struct CommandInfo { std::function handler; std::function autocomplete; // optional bool hidden = false; - bool requires_config = false; + bool requires_config = true; + bool requires_install = true; int min_args = 0; int max_args = -1; // -1 = unlimited std::string help_usage; // install SERVER [SERVICE] diff --git a/src/commands/help.cpp b/src/commands/help.cpp index e2fba72..6a054bd 100644 --- a/src/commands/help.cpp +++ b/src/commands/help.cpp @@ -28,6 +28,7 @@ struct HelpCommandRegister { help_autocomplete, false, // hidden false, // requires_config + false, // requires_install 0, // min_args (after command) 1, // max_args (after command) "help [COMMAND]", diff --git a/src/commands/install.cpp b/src/commands/install.cpp index 4636792..097341a 100644 --- a/src/commands/install.cpp +++ b/src/commands/install.cpp @@ -12,151 +12,178 @@ #include #include -namespace dropshell { +namespace dropshell +{ -int install_handler(const CommandContext& ctx); + int install_handler(const CommandContext &ctx); -static std::vector install_name_list={"install"}; + static std::vector install_name_list = {"install"}; -// Static registration -struct InstallCommandRegister { - InstallCommandRegister() { - CommandRegistry::instance().register_command({ - install_name_list, - install_handler, - std_autocomplete, - false, // hidden - false, // requires_config - 1, // min_args (after command) - 2, // max_args (after command) - "install SERVER [SERVICE]", - "Install/reinstall/update service(s). Safe/non-destructive.", - // heredoc - R"( - Install a service(s) on a server. - install (re)install the given service on the given server. - install (re)install all configured services on the given server. + // Static registration + struct InstallCommandRegister + { + InstallCommandRegister() + { + CommandRegistry::instance().register_command({install_name_list, + install_handler, + std_autocomplete_allowallservices, + false, // hidden + false, // requires_config + false, // requires_install + 1, // min_args (after command) + 2, // max_args (after command) + "install SERVER [SERVICE]", + "Install/reinstall/update service(s). Safe/non-destructive.", + // heredoc + R"( + Install components on a server. This is safe to re-run (non-destructive) and used to update + servers and their services. + + install (re)install dropshell components on this computer. + install SERVER (re)install dropshell agent on the given server. + install SERVER [SERVICE|*] (re)install the given service (or all services) on the given server. Note you need to create the service first with: dropshell create-service