_multipass 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #compdef multipass
  2. _multipass_get_command_list () {
  3. # Sample output:
  4. # $ multipass --help
  5. # ...
  6. # Options:
  7. # -h, --help Display this help
  8. # -v, --verbose Increase logging verbosity. Repeat the 'v' in the short option
  9. # for more detail. Maximum verbosity is obtained with 4 (or more)
  10. # v's, i.e. -vvvv.
  11. # ...
  12. # Available commands:
  13. # alias Create an alias
  14. # aliases List available aliases
  15. # ...
  16. #
  17. $_comp_command1 --help | sed '1,/Available commands/d' | awk '/^[ \t]*[a-z]+/ { print $1 }'
  18. }
  19. _multipass_get_args_list () {
  20. # Sample output:
  21. # $ multpass help stop
  22. # ...
  23. # Options:
  24. # -h, --help Display this help
  25. # -v, --verbose Increase logging verbosity. Repeat the 'v' in the short
  26. # option for more detail. Maximum verbosity is obtained with
  27. # 4 (or more) v's, i.e. -vvvv.
  28. # --all Stop all instances
  29. # -t, --time <time> Time from now, in minutes, to delay shutdown of the
  30. # instance
  31. # -c, --cancel Cancel a pending delayed shutdown
  32. #
  33. # Arguments:
  34. # name Names of instances to stop. If omitted, and without the
  35. # --all option, 'primary' will be assumed.
  36. #
  37. local arg_name=$($_comp_command1 help ${words[2]} | sed '1,/Arguments/d' | awk '/^[ \t]*[a-z]+/ { print $1; exit }')
  38. case $arg_name in
  39. name)
  40. # Sample output:
  41. # $ multipass list
  42. # Name State IPv4 Image
  43. # workable-poacher Running 10.2.0.28 Ubuntu openHAB Home Appliance
  44. #
  45. $_comp_command1 list | sed '1d' | awk '/^[ \t]*[^ ]+/ { print $1 }'
  46. ;;
  47. command)
  48. _multipass_get_command_list
  49. ;;
  50. esac
  51. }
  52. _multipass () {
  53. typeset -A opt_args
  54. _arguments \
  55. '1: :->command'\
  56. '*: :->args'
  57. case $state in
  58. command)
  59. compadd $(_multipass_get_command_list)
  60. ;;
  61. *)
  62. compadd $(_multipass_get_args_list)
  63. ;;
  64. esac
  65. }
  66. _multipass "$@"