Skip to content

Commit 918e18d

Browse files
committed
adding rule and policy completion logic
1 parent 266f69a commit 918e18d

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

contrib/completion/bash/netctl

+54-14
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,36 @@ _netctl_complete_tenants() {
2323
_netctl_complete_networks() {
2424
local tenant
2525
tenant=$(_netctl_fetch_tenant_value)
26-
fields='$2'
27-
COMPREPLY=( $(compgen -W '$(netctl network ls --tenant $tenant -q")' -- "$cur") )
26+
COMPREPLY=( $(compgen -W '$(netctl network ls --tenant $tenant -q)' -- "$cur") )
2827
}
2928

3029
# Fetch all policy names in the tenant
3130
_netctl_complete_policies() {
3231
local tenant
3332
tenant=$(_netctl_fetch_tenant_value)
34-
fields='$2'
3533
COMPREPLY=( $(compgen -W '$(netctl policy ls --tenant $tenant -q)' -- "$cur") )
3634
}
3735

3836
# Fetch all group names in the tenant
3937
_netctl_complete_groups() {
4038
local tenant
4139
tenant=$(_netctl_fetch_tenant_value)
42-
fields='$2'
43-
COMPREPLY=( $(compgen -W '$(netctl group ls --tenant $tenant -q")' -- "$cur") )
40+
COMPREPLY=( $(compgen -W '$(netctl group ls --tenant $tenant -q)' -- "$cur") )
41+
}
42+
43+
_netctl_complete_rules() {
44+
local tenant
45+
tenant=$(_netctl_fetch_tenant_value)
46+
policy=$(_netctl_fetch_policy_value)
47+
if [ -z $policy ]; then
48+
_netctl_fetch_options
49+
return
50+
fi
51+
COMPREPLY=( $(compgen -W '$(netctl rule ls --policy $policy --tenant $tenant -q)' -- "$cur") )
4452
}
4553

4654

55+
4756
_netctl() {
4857
local cur prev firstword secondword complete_words complete_options
4958

@@ -199,7 +208,7 @@ _netctl_network_rm() {
199208
case "$prev" in
200209
--tenant|-t)
201210
_netctl_complete_tenants
202-
return
211+
return
203212
;;
204213
esac
205214

@@ -217,7 +226,7 @@ _netctl_network_ls() {
217226
case "$prev" in
218227
--tenant|-t)
219228
_netctl_complete_tenants
220-
return
229+
return
221230
;;
222231
esac
223232

@@ -265,7 +274,7 @@ _netctl_policy_rm() {
265274
case "$prev" in
266275
--tenant|-t)
267276
_netctl_complete_tenants
268-
return
277+
return
269278
;;
270279
esac
271280

@@ -283,7 +292,7 @@ _netctl_policy_ls() {
283292
case "$prev" in
284293
--tenant|-t)
285294
_netctl_complete_tenants
286-
return
295+
return
287296
;;
288297
esac
289298

@@ -318,7 +327,7 @@ _netctl_group_rm() {
318327
case "$prev" in
319328
--tenant|-t)
320329
_netctl_complete_tenants
321-
return
330+
return
322331
;;
323332
esac
324333

@@ -336,7 +345,7 @@ _netctl_group_ls() {
336345
case "$prev" in
337346
--tenant|-t)
338347
_netctl_complete_tenants
339-
return
348+
return
340349
;;
341350
esac
342351

@@ -369,6 +378,10 @@ _netctl_rule_create() {
369378
COMPREPLY=( $( compgen -W "accept deny" -- "$cur" ) )
370379
return
371380
;;
381+
--policy|-p)
382+
_netctl_complete_policies
383+
return
384+
;;
372385
esac
373386

374387
case "$cur" in
@@ -383,22 +396,34 @@ _netctl_rule_rm() {
383396
case "$prev" in
384397
--tenant|-t)
385398
_netctl_complete_tenants
386-
return
399+
return
400+
;;
401+
--policy|-p)
402+
_netctl_complete_policies
403+
return
387404
;;
388405
esac
389406

390407
case "$cur" in
391408
-*)
392409
_netctl_fetch_options
393410
;;
411+
412+
*)
413+
_netctl_complete_rules
414+
;;
394415
esac
395416
}
396417

397418
_netctl_rule_ls() {
398419
case "$prev" in
399420
--tenant|-t)
400421
_netctl_complete_tenants
401-
return
422+
return
423+
;;
424+
--policy|-p)
425+
_netctl_complete_policies
426+
return
402427
;;
403428
esac
404429

@@ -446,7 +471,22 @@ _netctl_fetch_tenant_value() {
446471
echo $tenant
447472
}
448473

449-
# Parses the entire command for the option that is requested
474+
_netctl_fetch_policy_value() {
475+
local policy
476+
policy=$(_netctl_option_val_get '--policy')
477+
if [ -z $policy ]; then
478+
policy=$(_netctl_option_val_get '-p')
479+
480+
if [ -z $policy]
481+
then
482+
policy=""
483+
fi
484+
fi
485+
echo $policy
486+
}
487+
488+
489+
# Parses the entire command for the option that is requested
450490
# and returns the next pattern as value
451491
_netctl_option_val_get() {
452492
local option_prop option_val i

0 commit comments

Comments
 (0)