Exit with "Not found" message on failed search in `enable`/`disable`

When the search string in `enable` or `disable` is not found, exit the
program and provide feedback rather than silently failing.
This commit is contained in:
William Melody 2015-09-12 13:19:17 -07:00
parent 62f200574d
commit 8465c2bdf8
1 changed files with 10 additions and 0 deletions

10
hosts
View File

@ -725,6 +725,10 @@ disable() {
sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}"
)
_debug printf "disable() \$targets: %s\n" "$targets"
if [[ -z "${targets}" ]]
then
_die printf "Not found: %s\n" "${search_term}"
fi
printf "Disabling:\n%s\n" "${targets}"
@ -788,6 +792,12 @@ enable() {
local targets
targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}")
_debug printf "enable() \$targets: %s\n" "$targets"
if [[ -z "${targets}" ]]
then
_die printf "Not found: %s\n" "${search_term}"
fi
printf "Enabling:\n%s\n" "${targets}"
# -i '' - in place edit. BSD sed requires extension argument, for GNU