diff --git a/hosts b/hosts index bb5c4e8..9510f80 100755 --- a/hosts +++ b/hosts @@ -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}" diff --git a/test/show.bats b/test/show.bats index 5809762..8aa4924 100644 --- a/test/show.bats +++ b/test/show.bats @@ -19,6 +19,24 @@ load test_helper [[ "${lines[1]}" == " hosts show ( | | )" ]] } +# `hosts show ` ################################################## + +@test "\`show \` 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 ` ######################################################### @test "\`show \` exits with status 0 and shows all matches." {