1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-12-28 20:12:42 +00:00

Return 1 from show when entry not found.

GH-9
This commit is contained in:
William Melody 2020-04-22 11:53:40 -07:00
parent 5112c3e6a0
commit 88030b8a51
2 changed files with 25 additions and 1 deletions

8
hosts
View File

@ -1345,7 +1345,7 @@ Description:
Exit status:
0 Success.
1 Invalid parameters.
1 Invalid parameters or entry not found.
HEREDOC
show() {
if [[ -n "${1:-}" ]]
@ -1361,6 +1361,12 @@ show() {
grep --invert-match "^#" "${HOSTS_PATH}" | grep "${1}" || true
)"
if [[ -z "${_disabled_records}" ]] && [[ -z "${_enabled_records}" ]]
then
printf "No matching entries.\\n"
return 1
fi
_print_entries "${_enabled_records}"

View File

@ -19,6 +19,24 @@ load test_helper
[[ "${lines[1]}" == " hosts show (<ip> | <hostname> | <search string>)" ]]
}
# `hosts show <no matching>` ##################################################
@test "\`show <query>\` with no matching records with status 1." {
{
run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net
run "${_HOSTS}" add 127.0.0.2 example.com
run "${_HOSTS}" disable example.com
}
run "${_HOSTS}" show bad-query
printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 1 ]]
[[ "${lines[0]}" =~ No\ matching\ entries ]]
}
# `hosts show <ip>` #########################################################
@test "\`show <ip>\` exits with status 0 and shows all matches." {