_yosaictl 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #compdef yosaictl
  2. _yosaictl() {
  3. declare -A yosaictl_cmd
  4. output=$(yosaictl routes show)
  5. # Initialize a variable to hold the current category
  6. current_category=""
  7. # Parse the output
  8. while IFS= read -r line; do
  9. # Trim whitespace
  10. trimmed_line="${line:# }" # Removes leading tab
  11. # Check if the line starts with a non-tab character (a category)
  12. if [[ "$line" =~ ^[^[:space:]] ]]; then
  13. current_category="$trimmed_line"
  14. else
  15. # Add the command to the current category
  16. yosaictl_cmd[$current_category]+="${trimmed_line} "
  17. fi
  18. done <<< "$output"
  19. yosaictl routes show | grep -v '^\s' | tr '\n' ' ' | read -A elements
  20. local state
  21. _arguments \
  22. '1: :->yosaictl_target'\
  23. '*: :->target_method'
  24. case $state in
  25. (yosaictl_target) _arguments '1:cmd_targets:($elements)' ;;
  26. (*) compadd "$@" $(echo $yosaictl_cmd[$words[2]])
  27. esac
  28. }
  29. _yosaictl "$@"