More instructions

This commit is contained in:
Your Name
2025-04-25 23:29:50 +12:00
parent fb46dffdaf
commit 3c99ad1503
6 changed files with 103 additions and 25 deletions

View File

@ -29,6 +29,7 @@ void print_help() {
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/reinstall/update service(s). Non-destructive." << std::endl;
std::cout << " edit SERVER [SERVICE] Edit the configuration of the server/service." << std::endl;
std::cout << " COMMAND SERVER [SERVICE] Run a command on service(s)." << std::endl;
std::cout << std::endl;
std::cout << "Standard commands: install, uninstall, backup, restore, start, stop" << std::endl;
@ -114,25 +115,26 @@ int main(int argc, char* argv[]) {
}
// auto completion stuff.
std::set<std::string> commands;
std::set<std::string> template_shell_commands, full_command_set;
std::vector<dropshell::ServerInfo> servers = dropshell::get_configured_servers();
for (const auto& server : servers)
{
std::vector<dropshell::ServiceInfo> services = dropshell::get_server_services_info(server.name);
for (const auto& service : services)
commands.merge(dropshell::get_used_commands(server.name, service.service_name));
template_shell_commands.merge(dropshell::get_used_commands(server.name, service.service_name));
}
if (cmd == "autocomplete_list_commands") {
commands.merge(std::set<std::string>{
"help","init"
if (cmd == "autocomplete_list_commands") { // add in commands handled here, not by the template shell scripts.
std::set<std::string> full_command_set = template_shell_commands;
full_command_set.merge(std::set<std::string>{
"help","init" // these are always available.
});
if (cfg->is_config_set())
commands.merge(std::set<std::string>{
"server","templates","create-service","create-template","create-server","ssh"
full_command_set.merge(std::set<std::string>{
"server","templates","create-service","create-template","create-server","edit","ssh" // only if we have a config.
});
for (const auto& command : commands) {
for (const auto& command : full_command_set) {
std::cout << command << std::endl;
}
return 0;
@ -233,7 +235,19 @@ int main(int argc, char* argv[]) {
return 0;
}
if (cmd == "edit" && argc < 4) {
if (argc < 3)
{
std::cerr << "Error: edit requires a server name and optionally service name" << std::endl;
return 1;
}
dropshell::edit_server(argv[2]);
return 0;
}
// handle running a command.
std::set<std::string> commands = template_shell_commands;
commands.merge(std::set<std::string>{"ssh","edit"}); // handled by service_runner, but not in template_shell_commands.
for (const auto& command : commands) {
if (cmd == command) {
std::string server_name;
@ -260,6 +274,12 @@ int main(int argc, char* argv[]) {
// Unknown command
std::cerr << "Error: Unknown command '" << cmd << "'" << std::endl;
std::cerr << "Valid commands: ";
for (const auto& command : commands) {
std::cerr << command << " ";
}
std::cerr << std::endl;
// print help
dropshell::print_help();
return 1;