mirror of https://github.com/octoleo/hosts.git
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:
parent
62f200574d
commit
8465c2bdf8
10
hosts
10
hosts
|
@ -725,6 +725,10 @@ disable() {
|
||||||
sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}"
|
sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}"
|
||||||
)
|
)
|
||||||
_debug printf "disable() \$targets: %s\n" "$targets"
|
_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}"
|
printf "Disabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
|
@ -788,6 +792,12 @@ enable() {
|
||||||
|
|
||||||
local targets
|
local targets
|
||||||
targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}")
|
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}"
|
printf "Enabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
# -i '' - in place edit. BSD sed requires extension argument, for GNU
|
# -i '' - in place edit. BSD sed requires extension argument, for GNU
|
||||||
|
|
Loading…
Reference in New Issue