-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_multipass
137 lines (118 loc) · 2.98 KB
/
_multipass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#compdef multipass
# heavily based on _cvs and _adb
_multipass() {
_arguments \
'*::multipass command:_multipass_command'
}
# define multipass command dispatch function.
(( $+functions[_multipass_command] )) ||
_multipass_command() {
local ret=1
# multipass --help
# pbpaste | sed -E "s/^ */'/g; s/$/'/g; s/ {2,}/:/g" | tr '[:upper:]' '[:lower:]'
local -a commands
commands=(
'alias:create an alias'
'aliases:list available aliases'
'delete:delete instances'
'exec:run a command on an instance'
'find:display available images to create instances from'
'get:get a configuration setting'
'help:display help about a command'
'info:display information about instances'
'launch:create and start an ubuntu instance'
'list:list all available instances'
'mount:mount a local directory in the instance'
'networks:list available network interfaces'
'purge:purge all deleted instances permanently'
'recover:recover deleted instances'
'restart:restart instances'
'set:set a configuration setting'
'shell:open a shell on a running instance'
'start:start instances'
'stop:stop running instances'
'suspend:suspend running instances'
'transfer:transfer files between the host and instances'
'umount:unmount a directory from an instance'
'unalias:remove an alias'
'version:show version details:_version'
)
if (( CURRENT == 1 )); then
_describe -t commands 'multipass command' commands
else
_call_function ret _multipass_$words[1]
return ret
fi
}
_multipass_delete() {
_arguments \
--all \
+ '(purge)' \
{-p,--purge} \
'*::name:_instances'
}
_multipass_exec() {
_arguments \
':name:_instances_running'
}
_multipass_get() {
_arguments \
--raw \
':key:_configuration_settings'
}
_multipass_info() {
_arguments \
--all \
'--format: :(table json csv yaml)' \
':name:_instances'
}
_multipass_purge() {
# the purge subcommand takes no arguments
}
_multipass_restart() {
_arguments \
--all \
--timeout: \
':name:_instances_running'
}
_multipass_shell() {
_arguments \
--timeout: \
':name:_instances'
}
_multipass_start() {
_arguments \
--all \
--timeout: \
'::name:_instances'
}
_multipass_stop() {
_arguments \
--all \
+ '(time)' \
{-t,--time}: \
+ '(cancel)' \
{-c,--cancel} \
'*::name:_instances_running'
}
_multipass_version() {
_arguments \
'--format: :(table json csv yaml)'
}
_configuration_settings() {
local -a keys
keys=( $(multipass set --help | grep -E '(client|local)') )
_describe -t names 'keys' keys
}
_instances() {
# from _adb
local -a instances
instances=( $(multipass list --format csv | tail -n +2 | cut -f 1 -d ,) )
_describe -t names 'instances' instances
}
_instances_running() {
local -a instances
instances=( $(multipass list --format csv | tail -n +2 | grep Running | cut -f 1 -d ,) )
_describe -t names 'instances' instances
}
_multipass $@