Skip to content

Commit

Permalink
Handle 3rd-level arguments appropriately
Browse files Browse the repository at this point in the history
Before, `vcgencmd vcos 0` would inappropriately suggest display numbers.
  • Loading branch information
rgm3 committed Jul 9, 2021
1 parent 1edfb4e commit 53b8498
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
29 changes: 29 additions & 0 deletions host_applications/linux/apps/gencmd/vcgencmd-completion-test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ complete_command() {
fi
}

is_pi4() {
grep -qE '^Model.* Raspberry Pi 4' /proc/cpuinfo
}

@test "vcgencmd - -> -t -h --help" {
complete_command "vcgencmd -"
[[ "${COMPREPLY[*]}" == "-t -h --help" ]]
Expand Down Expand Up @@ -108,11 +112,31 @@ complete_command() {
[[ "${COMPREPLY[*]}" == "0 1" ]]
}

# Pi 4B has two hdmi pixel freq limits 0 and 1, Pi 2 and 3 just have one
@test "get_config hdmi_pixel_freq_li -> hdmi_pixel_freq_limit:0" {
if is_pi4; then
skip "test only valid with 1 hdmi (earlier pi models)"
fi
complete_command "vcgencmd get_config hdmi_pixel_freq_li"
[[ "${COMPREPLY[*]}" == "hdmi_pixel_freq_limit:0" ]]
}

@test "get_config hdmi_pixel_freq_li -> hdmi_pixel_freq_limit:" {
if ! is_pi4; then
skip "test requires Pi 4 with 2 hdmi outputs"
fi
complete_command "vcgencmd get_config hdmi_pixel_freq_li"
[[ "${COMPREPLY[*]}" == "hdmi_pixel_freq_limit:0 hdmi_pixel_freq_limit:1" ]]
}

@test "get_config hdmi_pixel_freq_limit: -> 0 1" {
if ! is_pi4; then
skip "test requires Pi 4 with 2 hdmi outputs"
fi
complete_command "vcgencmd get_config hdmi_pixel_freq_limit:"
[[ "${COMPREPLY[*]}" == "0 1" ]]
}

@test "vcos -> version log" {
complete_command "vcgencmd vcos "
echo "${COMPREPLY[*]}" | grep -Ewo "(version|log)"
Expand Down Expand Up @@ -168,3 +192,8 @@ complete_command() {
complete_command "vcgencmd -t vcos log "
[[ "${COMPREPLY[*]}" == "status" ]]
}

@test "vcos 0 -> (nothing)" {
complete_command "vcgencmd vcos 0 "
[[ "${#COMPREPLY[@]}" -eq 0 ]]
}
20 changes: 13 additions & 7 deletions host_applications/linux/apps/gencmd/vcgencmd-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ _vcgencmd() {
fi

if [[ $args -eq 3 ]]; then
case "$prev" in
0|1|-1)
opts='0 1 2 3 7'
case "${words[cword - 2]}" in
display_power)
case "$prev" in
0|1|-1)
opts='0 1 2 3 7'
;;
esac
;;
esac
case "$prev" in
log)
opts='status'
vcos)
case "$prev" in
log)
opts='status'
;;
esac
;;
esac
fi
Expand Down

0 comments on commit 53b8498

Please sign in to comment.