Skip to content

Commit d162e3a

Browse files
authored
Bash completion for chip example applications (#36841)
1 parent 9451aa5 commit d162e3a

File tree

1 file changed

+89
-15
lines changed

1 file changed

+89
-15
lines changed

scripts/helpers/bash-completion.sh

+89-15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,58 @@ _chip_tool_get_options() {
2828
"$@" --help 2>&1 | awk -F'[[]|[]]' '/^[[]--/{ print $2 }'
2929
}
3030

31+
_chip_app() {
32+
33+
local cur prev words cword split
34+
_init_completion -s || return
35+
36+
case "$prev" in
37+
--ble-device)
38+
readarray -t words < <(ls -I '*:*' /sys/class/bluetooth)
39+
# Get the list of Bluetooth devices without the 'hci' prefix.
40+
readarray -t COMPREPLY < <(compgen -W "${words[*]#hci}" -- "$cur")
41+
return
42+
;;
43+
--custom-flow)
44+
readarray -t COMPREPLY < <(compgen -W "0 1 2" -- "$cur")
45+
return
46+
;;
47+
--capabilities)
48+
# The capabilities option is a bit-field with 3 bits currently defined.
49+
readarray -t COMPREPLY < <(compgen -W "001 010 011 100 101 111" -- "$cur")
50+
return
51+
;;
52+
--KVS)
53+
_filedir
54+
return
55+
;;
56+
--PICS)
57+
_filedir
58+
return
59+
;;
60+
--trace_file)
61+
_filedir
62+
return
63+
;;
64+
--trace_log | --trace_decode)
65+
readarray -t COMPREPLY < <(compgen -W "0 1" -- "$cur")
66+
return
67+
;;
68+
--trace-to)
69+
readarray -t COMPREPLY < <(compgen -W "json perfetto" -- "$cur")
70+
compopt -o nospace
71+
return
72+
;;
73+
esac
74+
75+
case "$cur" in
76+
-*)
77+
readarray -t COMPREPLY < <(compgen -W "$(_parse_help "$1")" -- "$cur")
78+
;;
79+
esac
80+
81+
}
82+
3183
_chip_tool() {
3284

3385
local cur prev words cword split
@@ -36,34 +88,56 @@ _chip_tool() {
3688
# Get command line arguments up to the cursor position
3789
local args=("${COMP_WORDS[@]:0:$cword+1}")
3890

39-
local command=0
4091
case "$prev" in
4192
--commissioner-name)
4293
readarray -t COMPREPLY < <(compgen -W "alpha beta gamma 4 5 6 7 8 9" -- "$cur")
94+
return
95+
;;
96+
--only-allow-trusted-cd-keys)
97+
readarray -t COMPREPLY < <(compgen -W "0 1" -- "$cur")
98+
return
4399
;;
44-
--paa-trust-store-path | --cd-trust-store-path)
100+
--paa-trust-store-path | --cd-trust-store-path | --dac-revocation-set-path)
45101
_filedir -d
102+
return
46103
;;
47104
--storage-directory)
48105
_filedir -d
106+
return
49107
;;
50-
*)
51-
command=1
108+
--trace-to)
109+
readarray -t COMPREPLY < <(compgen -W "json perfetto" -- "$cur")
110+
compopt -o nospace
111+
return
52112
;;
53113
esac
54114

55-
if [ "$command" -eq 1 ]; then
56-
case "$cur" in
57-
-*)
58-
words=$(_chip_tool_get_options "${args[@]}")
59-
;;
60-
*)
61-
words=$(_chip_tool_get_commands "${args[@]}")
62-
;;
63-
esac
64-
readarray -t COMPREPLY < <(compgen -W "$words" -- "$cur")
65-
fi
115+
case "$cur" in
116+
-*)
117+
words=$(_chip_tool_get_options "${args[@]}")
118+
;;
119+
*)
120+
words=$(_chip_tool_get_commands "${args[@]}")
121+
;;
122+
esac
123+
readarray -t COMPREPLY < <(compgen -W "$words" -- "$cur")
66124

67125
}
68126

127+
complete -F _chip_app chip-air-purifier-app
128+
complete -F _chip_app chip-all-clusters-app
129+
complete -F _chip_app chip-bridge-app
130+
complete -F _chip_app chip-dishwasher-app
131+
complete -F _chip_app chip-energy-management-app
132+
complete -F _chip_app chip-lighting-app
133+
complete -F _chip_app chip-lock-app
134+
complete -F _chip_app chip-log-source-app
135+
complete -F _chip_app chip-microwave-oven-app
136+
complete -F _chip_app chip-ota-provider-app
137+
complete -F _chip_app chip-ota-requestor-app
138+
complete -F _chip_app chip-refrigerator-app
139+
complete -F _chip_app chip-rvc-app
140+
complete -F _chip_app chip-tv-app
141+
complete -F _chip_app chip-tv-casting-app
142+
69143
complete -F _chip_tool chip-tool

0 commit comments

Comments
 (0)