|
| 1 | +# Disable file completions globally for spm |
| 2 | +complete -c spm -f |
| 3 | + |
| 4 | +# Helper function to check if spm has not received a subcommand |
| 5 | +function __fish_spm_no_subcommand --description "Check if spm has not received a subcommand" |
| 6 | + for i in (commandline -opc) |
| 7 | + if contains -- $i start stop kill logs list jlist restart flush rotate |
| 8 | + return 1 |
| 9 | + end |
| 10 | + end |
| 11 | + return 0 |
| 12 | +end |
| 13 | + |
| 14 | +# Dynamic service names completion using spm jlist |
| 15 | +function __fish_spm_process_names --description "Fetch list of spm services" |
| 16 | + spm jlist 2>/dev/null | jq -r '.[].name' |
| 17 | +end |
| 18 | + |
| 19 | +# Root-level subcommands with descriptions |
| 20 | +complete -c spm -n '__fish_spm_no_subcommand' -a "start" -d "Start service instance(s)" |
| 21 | +complete -c spm -n '__fish_spm_no_subcommand' -a "stop" -d "Stop service instance(s)" |
| 22 | +complete -c spm -n '__fish_spm_no_subcommand' -a "kill" -d "Alias for 'stop'" |
| 23 | +complete -c spm -n '__fish_spm_no_subcommand' -a "logs" -d "Display logs for service instance(s)" |
| 24 | +complete -c spm -n '__fish_spm_no_subcommand' -a "list" -d "List services with running PIDs" |
| 25 | +complete -c spm -n '__fish_spm_no_subcommand' -a "jlist" -d "List services in JSON format" |
| 26 | +complete -c spm -n '__fish_spm_no_subcommand' -a "restart" -d "Restart service instance(s)" |
| 27 | +complete -c spm -n '__fish_spm_no_subcommand' -a "flush" -d "Clear log file contents" |
| 28 | +complete -c spm -n '__fish_spm_no_subcommand' -a "rotate" -d "Manage log rotation" |
| 29 | + |
| 30 | +# Dynamic service name completion for commands that take a service argument |
| 31 | +for cmd in start stop restart logs flush kill |
| 32 | + complete -c spm -n "__fish_seen_subcommand_from $cmd" -a "(__fish_spm_process_names)" -d "Service names" |
| 33 | +end |
| 34 | + |
| 35 | +# Subcommand-specific completions for the logs command |
| 36 | +complete -c spm -n '__fish_seen_subcommand_from logs' -a '--tail' -d "Tail log files in real time" |
| 37 | +complete -c spm -n '__fish_seen_subcommand_from logs' -a '-n --lines' -d "Number of lines to show" |
| 38 | +complete -c spm -n '__fish_seen_subcommand_from logs' -a '-f --filter' -d "Filter logs by pattern" |
| 39 | +complete -c spm -n '__fish_seen_subcommand_from logs' -a '-h --help' -d "Show help" |
| 40 | + |
| 41 | +# Completions for the rotate subcommand group |
| 42 | +complete -c spm -n '__fish_seen_subcommand_from rotate' -a "start" -d "Perform log rotation and spawn rotate-watch process" |
| 43 | +complete -c spm -n '__fish_seen_subcommand_from rotate' -a "watch" -d "Continuously watch and rotate logs" |
| 44 | +complete -c spm -n '__fish_seen_subcommand_from rotate' -a "stop" -d "Stop the rotate-watch process" |
0 commit comments