This commit is contained in:
Your Name 2025-04-21 13:04:13 +12:00
parent 0bb098b3f1
commit 32413f17bd
3 changed files with 45 additions and 1 deletions

View File

@ -7,7 +7,7 @@ _dropshell_completions() {
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
# List of main commands # List of main commands
opts="help version status servers templates autocomplete_list_servers autocomplete_list_services" opts="help version status servers templates autocomplete_list_servers autocomplete_list_services run"
# If we're completing the first argument, show all commands # If we're completing the first argument, show all commands
if [[ ${COMP_CWORD} -eq 1 ]] ; then if [[ ${COMP_CWORD} -eq 1 ]] ; then
@ -37,7 +37,29 @@ _dropshell_completions() {
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0 return 0
;; ;;
run)
# First argument after run is server name
local servers=($(dropshell autocomplete_list_servers))
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0
;;
*) *)
# Handle completion for service names and commands after run
if [[ ${COMP_CWORD} -ge 2 ]] && [[ "${COMP_WORDS[1]}" == "run" ]]; then
if [[ ${COMP_CWORD} -eq 3 ]]; then
# Second 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
elif [[ ${COMP_CWORD} -eq 4 ]]; then
# Third argument is command name
# For now, we'll just complete with common commands
local common_commands="status start stop update backup"
COMPREPLY=( $(compgen -W "${common_commands}" -- ${cur}) )
return 0
fi
fi
;; ;;
esac esac
} }

View File

@ -17,12 +17,14 @@ void print_help(const boost::program_options::options_description& desc) {
std::cout << " servers List configured servers" << std::endl; std::cout << " servers List 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 available templates" << std::endl; std::cout << " templates List available templates" << std::endl;
std::cout << " run SERVER SERVICE COMMAND Run a command on a specific service" << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << "Examples:" << std::endl; std::cout << "Examples:" << std::endl;
std::cout << " dropshell servers" << std::endl; std::cout << " dropshell servers" << std::endl;
std::cout << " dropshell servers myserver" << std::endl; std::cout << " dropshell servers myserver" << std::endl;
std::cout << " dropshell init /path/to/directory" << std::endl; std::cout << " dropshell init /path/to/directory" << std::endl;
std::cout << " dropshell templates" << std::endl; std::cout << " dropshell templates" << std::endl;
std::cout << " dropshell run myserver myservice status" << std::endl;
} }
} // namespace dropshell } // namespace dropshell

View File

@ -93,6 +93,26 @@ int main(int argc, char* argv[]) {
std::cout << service << std::endl; std::cout << service << std::endl;
} }
return 0; return 0;
} else if (cmd == "run") {
if (argc < 5) {
std::cerr << "Error: run command requires server name, service name, and command" << std::endl;
return 1;
}
std::string server_name = argv[2];
std::string service_name = argv[3];
std::string command = argv[4];
dropshell::server_service service;
if (!service.init(server_name, service_name)) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}
if (!service.run_command(command)) {
std::cerr << "Error: Failed to run command" << std::endl;
return 1;
}
return 0;
} else { } else {
std::cerr << "Error: Unknown command '" << cmd << "'" << std::endl; std::cerr << "Error: Unknown command '" << cmd << "'" << std::endl;
dropshell::print_help(desc); dropshell::print_help(desc);