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