26763: fix problem on failed cd -s to relative path
[zsh.git] / Completion / Solaris / Command / _dladm
blobd99fdc0e4fc48fb66cc2c6be598995ccdbd5c92a
1 #compdef dladm
3 _dladm_links() {
4         compadd "$@" - $(dladm show-link -p -o link)
7 _dladm_devs() {
8         compadd "$@" - $(dladm show-phys -p -o device)
11 _dladm_aggrs() {
12         compadd "$@" - $(dladm show-aggr -p -o link)
15 _dladm_aggr_ports() {
16         compadd "$@" - $(dladm show-aggr -p -x -o ports)
19 _dladm_vlans() {
20         compadd "$@" - $(dladm show-vlan -p -o link)
23 _dladm_wifi_links() {
24         compadd "$@" - $(dladm show-wifi -p -o link)
27 _dladm_wifi_nets() {
28         compadd "$@" - ${(f)"$(dladm scan-wifi -p -o essid)"}
31 _dladm_secobjs() {
32         compadd "$@" - ${(f)"$(dladm show-secobj -p -o object)"}
35 _dladm_ethers() {
36         compadd "$@" - $(dladm show-ether -p -o link)
39 _dladm_linkprops() {
40         # TODO: complete property values, when available
41         compadd "$@" - $(dladm show-linkprop -c -o property)
44 _dladm_vnics() {
45         compadd "$@" - $(dladm show-vnic -p -o link)
48 _dladm_etherstubs() {
49         compadd "$@" - $(dladm show-etherstub)
52 _dladm() {
53         local context state line expl
54         typeset -A opt_args
55         local -a subcmds rw_properties rw_propnames ro_properties
56         local -a link_properties link_stats_properties
57         local -a aggr_properties aggr_lacp_properties aggr_ext_properties
58         local -a vlan_properties wifi_properties wifi_connect_properties
59         local -a ether_properties linkprop_properties secobj_properties
61         # TODO: some subcommands can take multiple comma-separated targets
62         # TODO: some option sets may be different based on other commandline flags
63         # TODO: some subcommands may take different arguments based on options
65         subcmds=(
66                 "show-ether" "show-usage"
67                 {"rename","show"}"-link"
68                 {"add","create","delete","modify","remove","show"}"-aggr"
69                 {"connect","disconnect","scan","show"}"-wifi"
70                 {"reset","set","show"}"-linkprop"
71                 {"create","delete","show"}"-secobj"
72                 {"create","delete","show"}"-vlan"
73                 {"delete","show"}"-phys"
74                 {"create","delete","show"}"-vnic"
75                 {"create","delete","show"}"-etherstub"
76         )
78         if [[ $service == "dladm" ]]; then
79                 _arguments -C -A "-*" \
80                         '-\?[Help]' \
81                         '*::command:->subcmd' && return 0
83                 if (( CURRENT == 1 )); then
84                         _wanted commands expl "dladm subcommand" compadd -a subcmds
85                         return
86                 fi
87                 service="$words[1]"
88                 curcontext="${curcontext%:*}=$service:"
89         fi
91         link_properties=( "link" "class" "mtu" "state" "over" )
92         link_stats_properties=( "link" "ipackets" "rbytes" "ierrors" "opackets" "obytes" "oerrors" )
94         aggr_properties=( "link" "policy" "addrpolicy" "lacpactivity" "lacptimer" "flags" )
95         aggr_lacp_properties=( "link" "port" "aggregatable" "sync" "coll" "dist" "defaulted" "expired" )
96         aggr_ext_properties=( "link" "port" "speed" "duplex" "state" "address" "portstate" )
98         vlan_properties=( "link" "vid" "over" "flags" )
100         wifi_connect_properties=( "link" "essid" "bssid" "sec" "mode" "strength" "speed" "bsstype" )
101         wifi_properties=( $wifi_connect_properties "status" "auth" )
103         ether_properties=( "link" "ptype" "state" "auto" "speed-duplex" "pause" "rem_fault" )
105         linkprop_properties=( "link" "property" "value" "default" "possible" )
107         secobj_properties=( "object" "class" )
109         vnic_properties=( "link" "over" "speed" "macaddr" "macaddrtype" )
111         case $service in
112         ("show-link")
113                 _arguments -A "-*" \
114                         '(-P --persistent)'{-P,--persistent}'[Display persistent link configuration]' \
115                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
116                         - set1 \
117                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $link_properties' \
118                         - set2 \
119                         '(-s --statistics)'{-s,--statistics}'[Display link statistics]' \
120                         '(-i --interval)'{-i,--interval}'[Specify an interval]:interval:' \
121                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $link_stats_properties' \
122                         ':link name:_dladm_links' \
123                 ;;
125         ("rename-link")
126                 _arguments -A "-*" \
127                         '-R[Root directory]:directory:_path_files -/' \
128                         ':old link name:_dladm_links' \
129                         ':new link name:' \
130                 ;;
132         ("show-phys")
133                 _arguments -A "-*" \
134                         '(-P --persistent)'{-P,--persistent}'[Display persistent link configuration]' \
135                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
136                         '(-s --statistics)'{-s,--statistics}'[Display link statistics]' \
137                         '(-i --interval)'{-i,--interval}'[Specify an interval]:interval:' \
138                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" link media state speed duplex device' \
139                         ':physical link name:_dladm_devs'
140                 ;;
142         ("delete-phys")
143                 _arguments -A "-*" \
144                         ':physical link name:_dladm_devs'
145                 ;;
147         ("create-aggr")
148                 _arguments -A "-*" \
149                         '(-t --temporary)'{-t,--temporary}'[Aggregation should be temporary]' \
150                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
151                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_links' \
152                         '(-P --policy)'{-P,--policy}'[Port selection policy]:policy:_values -s , "policy" L2 L3 L4' \
153                         '(-L --lacp-mode)'{-L,--lacp-mode}'[LACP mode]:lacp mode:(off active passive)' \
154                         '(-T --lacp-timer)'{-T,--lacp-timer}'[LACP timer]:lacp timer:(short long)' \
155                         '(-u --unicast)'{-u,--unicast}'[Unicast address]:unicast address:' \
156                         ':aggregate link name:'
157                 ;;
159         ("modify-aggr")
160                 _arguments -A "-*" \
161                         '(-t --temporary)'{-t,--temporary}'[Aggregation should be temporary]' \
162                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
163                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_links' \
164                         '(-P --policy)'{-P,--policy}'[Port selection policy]:policy:_values -s , "policy" L2 L3 L4' \
165                         '(-L --lacp-mode)'{-L,--lacp-mode}'[LACP mode]:lacp mode:(off active passive)' \
166                         '(-T --lacp-timer)'{-T,--lacp-timer}'[LACP timer]:lacp timer:(short long)' \
167                         '(-u --unicast)'{-u,--unicast}'[Unicast address]:unicast address:' \
168                         ':aggregate link name:_dladm_aggrs'
169                 ;;
171         ("delete-aggr")
172                 _arguments -A "-*" \
173                         '(-t --temporary)'{-t,--temporary}'[Deletion should be temporary]' \
174                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
175                         ':aggregate link name:_dladm_aggrs'
176                 ;;
178         ("add-aggr")
179                 _arguments -A "-*" \
180                         '(-t --temporary)'{-t,--temporary}'[Aggregation should be temporary]' \
181                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
182                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_links' \
183                         ':aggregate link name:_dladm_aggrs'
184                 ;;
186         ("remove-aggr")
187                 _arguments -A "-*" \
188                         '(-t --temporary)'{-t,--temporary}'[Aggregation should be temporary]' \
189                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
190                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_aggr_ports' \
191                         ':aggregate link name:_dladm_aggrs'
192                 ;;
194         ("show-aggr")
195                 _arguments -A "-*" \
196                         '(-P --persistent)'{-P,--persistent}'[Display persistent link configuration]' \
197                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
198                         '(-s --statistics)'{-s,--statistics}'[Display link statistics]' \
199                         '(-i --interval)'{-i,--interval}'[Specify an interval]:interval:' \
200                         ':aggregate link name:_dladm_links' \
201                         - set1 \
202                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $aggr_properties' \
203                         - lacp \
204                         '(-L --lacp)'{-L,--lacp}'[LACP information]' \
205                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $aggr_lacp_properties' \
206                         - extended \
207                         '(-x --extended)'{-x,--extended}'[Extended information]' \
208                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $aggr_ext_properties' \
209                 ;;
211         ("create-vlan")
212                 _arguments -A "-*" \
213                         '(-t --temporary)'{-t,--temporary}'[VLAN should be temporary]' \
214                         '(-f --force)'{-f,--force}'[Force VLAN creation]' \
215                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
216                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_links' \
217                         '-v[VLAN ID]:id:' \
218                         ':VLAN link name:'
219                 ;;
221         ("delete-vlan")
222                 _arguments -A "-*" \
223                         '(-t --temporary)'{-t,--temporary}'[Deletion should be temporary]' \
224                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
225                         ':VLAN link name:_dladm_vlans'
226                 ;;
228         ("show-vlan")
229                 _arguments -A "-*" \
230                         '(-P --persistent)'{-P,--persistent}'[Display persistent link configuration]' \
231                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
232                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $vlan_properties' \
233                         ':VLAN link name:_dladm_vlans'
234                 ;;
236         ("scan-wifi")
237                 _arguments -A "-*" \
238                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
239                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $wifi_connect_properties' \
240                         ':wireless link name:_dladm_wifi_links'
241                 ;;
243         ("connect-wifi")
244                 _arguments -A "-*" \
245                         '(-e --essid)'{-e,--essid}'[ESSID name]:network:_dladm_wifi_nets' \
246                         '(-b --bsstype)'{-b,--bsstype}'[BSS type]:' \
247                         '(-m --mode)'{-m,--mode}'[802.11 mode]:mode:(a b g)' \
248                         '(-k --key)'{-k,--key}'[Key name]:key:_dladm_secobjs' \
249                         '(-s --sec)'{-s,--sec}'[Security mode]:(none wep wpa)' \
250                         '(-a --auth)'{-a,--auth}'[Authentication mode]:mode:(open shared)' \
251                         '(-c --create-ibss)'{-c,--create-ibss}'[Create an ad-hoc network]' \
252                         '(-T --timeout)'{-T,--timeout}'[Association timeout]:(forever)' \
253                         ':wireless link name:_dladm_wifi_links'
254                 ;;
256         ("disconnect-wifi")
257                 _arguments -A "-*" \
258                         - set1 \
259                         '(-a --all-links)'{-a,--all-links}'[All links]' \
260                         - set2 \
261                         ':wireless link name:_dladm_wifi_links'
262                 ;;
264         ("show-wifi")
265                 _arguments -A "-*" \
266                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
267                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $wifi_properties' \
268                         ':wireless link name:_dladm_wifi_links'
269                 ;;
271         ("show-ether")
272                 _arguments -A "-*" \
273                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
274                         '(-x --extended)'{-x,--extended}'[Extended output]' \
275                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $ether_properties' \
276                         ':ethernet link name:_dladm_ethers'
277                 ;;
279         ("set-linkprop")
280                 _arguments -A "-*" \
281                         '(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
282                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
283                         '(-p --prop)'{-p,--prop}'[Properties]:property:_dladm_linkprops' \
284                         ':link name:_dladm_links'
285                 ;;
287         ("reset-linkprop")
288                 _arguments -A "-*" \
289                         '(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
290                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
291                         '(-p --prop)'{-p,--prop}'[Properties]:property:_dladm_linkprops' \
292                         ':link name:_dladm_links'
293                 ;;
295         ("show-linkprop")
296                 _arguments -A "-*" \
297                         '(-P --persistent)'{-P,--persistent}'[Display persistent link properties]' \
298                         '(-c --parseable)'{-c,--parseable}'[Parseable output]' \
299                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $linkprop_properties' \
300                         '(-p --prop)'{-p,--prop}'[Properties]:property:_dladm_linkprops' \
301                         ':link name:_dladm_links'
302                 ;;
304         ("create-secobj")
305                 _arguments -A "-*" \
306                         '(-t --temporary)'{-t,--temporary}'[Creation should be temporary]' \
307                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
308                         '(-c --class)'{-c,--class}'[Class]:class:(wep wpa)' \
309                         '(-f --file)'{-f,--file}'[File containing object value]:file:_path_files' \
310                         ':object name:'
311                 ;;
313         ("delete-secobj")
314                 _arguments -A "-*" \
315                         '(-t --temporary)'{-t,--temporary}'[Deletion should be temporary]' \
316                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
317                         ':object name:_dladm_secobjs'
318                 ;;
320         ("show-secobj")
321                 _arguments -A "-*" \
322                         '(-P --persistent)'{-P,--persistent}'[Display persistent object information]' \
323                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
324                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $secobj_properties' \
325                         ':object name:_dladm_secobjs'
326                 ;;
328         ("create-vnic")
329                 # TODO: MAC address completion could be richer
330                 _arguments -A "-*" \
331                         '(-t --temporary)'{-t,--temporary}'[Creation should be temporary]' \
332                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
333                         '(-l --link)'{-l,--link}'[Component link]:link:_dladm_links' \
334                         '(-m --mac-address)'{-m,--mac-address}'[MAC address]:address:(factory random auto)' \
335                         '-v[VLAN ID]:id:' \
336                         '(-p --prop)'{-p,--prop}'[Property values]:value:' \
337                         ':VNIC name:'
338                 ;;
340         ("delete-vnic")
341                 _arguments -A "-*" \
342                         '(-t --temporary)'{-t,--temporary}'[Deletion should be temporary]' \
343                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
344                         ':VNIC name:_dladm_vnics'
345                 ;;
347         ("show-vnic")
348                 _arguments -A "-*" \
349                         '(-P --persistent)'{-P,--persistent}'[Display persistent object information]' \
350                         '(-p --parseable)'{-p,--parseable}'[Parseable output]' \
351                         '(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $vnic_properties' \
352                         '(-l --link)'{-l,--link}'[Limit to VNICs on link]:link:_dladm_links' \
353                         '(-s --statistics)'{-s,--statistics}'[Display VNIC statistics]' \
354                         '(-i --interval)'{-i,--interval}'[Specify an interval]:interval:' \
355                         ':VNIC name:_dladm_vnics'
356                 ;;
358         ("create-etherstub")
359                 _arguments -A "-*" \
360                         '(-t --temporary)'{-t,--temporary}'[Creation should be temporary]' \
361                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
362                         ':etherstub name:'
363                 ;;
365         ("delete-etherstub")
366                 _arguments -A "-*" \
367                         '(-t --temporary)'{-t,--temporary}'[Deletion should be temporary]' \
368                         '(-R --root)'{-R,--root}'[Root directory]:directory:_path_files -/' \
369                         ':etherstub name:_dladm_etherstubs'
370                 ;;
372         ("show-etherstub")
373                 _arguments -A "-*" \
374                         ':etherstub name:_dladm_etherstubs'
375                 ;;
377         ("show-usage")
378                 _arguments -A "-*" \
379                         '(-f --file)'{-f,--file}'[Read records from file]:_path_files' \
380                         '(-F --format)'{-f,--format}'[Plotfile format]:(gnuplot)' \
381                         '(-p --plot)'{-p,--plot}'[Write plot to file]:' \
382                         '(-e --start)'{-e,--start}'[Start time]:date/time (MM/DD/YYYY,hh\:mm\:ss)' \
383                         '(-s --stop)'{-s,--stop}'[Stop time]:date/time (MM/DD/YYYY,hh\:mm\:ss)' \
384                         ':link name:_dladm_links'
385                 ;;
387         (*)
388                 _message "unknown dladm subcommand: $service"
389                 ;;
390         esac
393 _dladm "$@"