Use 'entries' terminology consistently.

This commit is contained in:
William Melody 2020-09-11 17:46:18 -07:00
parent 06ad3e8deb
commit 80699292a4
8 changed files with 60 additions and 60 deletions

View File

@ -159,7 +159,7 @@ address, domain, or regular expression:
```bash ```bash
> hosts remove example.com > hosts remove example.com
Removing the following records: Removing the following entries:
127.0.0.1 example.com 127.0.0.1 example.com
Are you sure you want to proceed? [y/N] y Are you sure you want to proceed? [y/N] y
Removed: Removed:
@ -401,7 +401,7 @@ Usage:
Description: Description:
List the existing IP / hostname pairs, optionally limited to a specified List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a seach string, all matching enabled records will state. When provided with a seach string, all matching enabled entries will
be printed. be printed.
Alias for `hosts list` Alias for `hosts list`
@ -496,7 +496,7 @@ Usage:
hosts disable (<ip> | <hostname> | <search string>) hosts disable (<ip> | <hostname> | <search string>)
Description: Description:
Disable one or more records based on a given ip address, hostname, or Disable one or more entries based on a given ip address, hostname, or
search string. search string.
Exit status: Exit status:
@ -511,7 +511,7 @@ Usage:
hosts disabled hosts disabled
Description: Description:
List all disabled records. This is an alias for `hosts list disabled`. List all disabled entries. This is an alias for `hosts list disabled`.
Exit status: Exit status:
0 One or more disabled entries found. 0 One or more disabled entries found.
@ -535,7 +535,7 @@ Usage:
hosts enable (<ip> | <hostname> | <search string>) hosts enable (<ip> | <hostname> | <search string>)
Description: Description:
Enable one or more disabled records based on a given ip address, hostname, Enable one or more disabled entries based on a given ip address, hostname,
or search string. or search string.
Exit status: Exit status:
@ -550,7 +550,7 @@ Usage:
hosts enabled hosts enabled
Description: Description:
List all enabled records. This is an alias for `hosts list enabled`. List all enabled entries. This is an alias for `hosts list enabled`.
Exit status: Exit status:
0 One or more enabled entries found. 0 One or more enabled entries found.
@ -585,7 +585,7 @@ Usage:
Description: Description:
List the existing IP / hostname pairs, optionally limited to a specified List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a seach string, all matching enabled records will state. When provided with a seach string, all matching enabled entries will
be printed. be printed.
Exit status: Exit status:
@ -604,8 +604,8 @@ Options:
--force Skip the confirmation prompt. --force Skip the confirmation prompt.
Description: Description:
Remove one or more records based on a given IP address, hostname, or search Remove one or more entries based on a given IP address, hostname, or search
string. If an IP and hostname are both provided, only records matching the string. If an IP and hostname are both provided, only entries matching the
IP and hostname pair will be removed. IP and hostname pair will be removed.
Exit status: Exit status:

76
hosts
View File

@ -1064,7 +1064,7 @@ Usage:
${_ME} disable (<ip> | <hostname> | <search string>) ${_ME} disable (<ip> | <hostname> | <search string>)
Description: Description:
Disable one or more records based on a given ip address, hostname, or Disable one or more entries based on a given ip address, hostname, or
search string. search string.
Exit status: Exit status:
@ -1130,7 +1130,7 @@ Usage:
${_ME} disabled ${_ME} disabled
Description: Description:
List all disabled records. This is an alias for \`hosts list disabled\`. List all disabled entries. This is an alias for \`hosts list disabled\`.
Exit status: Exit status:
0 One or more disabled entries found. 0 One or more disabled entries found.
@ -1167,7 +1167,7 @@ Usage:
${_ME} enable (<ip> | <hostname> | <search string>) ${_ME} enable (<ip> | <hostname> | <search string>)
Description: Description:
Enable one or more disabled records based on a given ip address, hostname, Enable one or more disabled entries based on a given ip address, hostname,
or search string. or search string.
Exit status: Exit status:
@ -1233,7 +1233,7 @@ Usage:
${_ME} enabled ${_ME} enabled
Description: Description:
List all enabled records. This is an alias for \`hosts list enabled\`. List all enabled entries. This is an alias for \`hosts list enabled\`.
Exit status: Exit status:
0 One or more enabled entries found. 0 One or more enabled entries found.
@ -1264,7 +1264,7 @@ Usage:
Description: Description:
List the existing IP / hostname pairs, optionally limited to a specified List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a seach string, all matching enabled records will state. When provided with a seach string, all matching enabled entries will
be printed. be printed.
Exit status: Exit status:
@ -1272,15 +1272,15 @@ Exit status:
1 Invalid parameters or entry not found. 1 Invalid parameters or entry not found.
HEREDOC HEREDOC
list() { list() {
local _disabled_records local _disabled_entries
_disabled_records=$( _disabled_entries=$(
sed -n "s/^\\#disabled: \\(.*\\)$/\\1/p" "${HOSTS_PATH}" sed -n "s/^\\#disabled: \\(.*\\)$/\\1/p" "${HOSTS_PATH}"
) )
# NOTE: use separate expressions since using `|` for the 'or' results in # NOTE: use separate expressions since using `|` for the 'or' results in
# inconsistent behavior. # inconsistent behavior.
local _enabled_records local _enabled_entries
_enabled_records="$( _enabled_entries="$(
grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}"
)" )"
@ -1288,28 +1288,28 @@ list() {
then then
if [[ "${1}" == "disabled" ]] if [[ "${1}" == "disabled" ]]
then then
[[ -z "${_disabled_records}" ]] && return 1 [[ -z "${_disabled_entries}" ]] && return 1
_print_entries "${_disabled_records}" _print_entries "${_disabled_entries}"
elif [[ "${1}" == "enabled" ]] elif [[ "${1}" == "enabled" ]]
then then
[[ -z "${_enabled_records}" ]] && return 1 [[ -z "${_enabled_entries}" ]] && return 1
_print_entries "${_enabled_records}" _print_entries "${_enabled_entries}"
else else
show "${1}" show "${1}"
fi fi
else else
[[ -z "${_enabled_records}" ]] && [[ -z "${_enabled_entries}" ]] &&
[[ -z "${_enabled_records}" ]] && [[ -z "${_enabled_entries}" ]] &&
return 1 return 1
_print_entries "${_enabled_records:-}" _print_entries "${_enabled_entries:-}"
if [[ -n "${_disabled_records:-}" ]] if [[ -n "${_disabled_entries:-}" ]]
then then
[[ -n "${_enabled_records:-}" ]] && printf "\\n" [[ -n "${_enabled_entries:-}" ]] && printf "\\n"
printf "Disabled:\\n" printf "Disabled:\\n"
printf "%s\\n" "---------" printf "%s\\n" "---------"
_print_entries "${_disabled_records}" _print_entries "${_disabled_entries}"
fi fi
fi fi
} }
@ -1325,8 +1325,8 @@ Options:
--force Skip the confirmation prompt. --force Skip the confirmation prompt.
Description: Description:
Remove one or more records based on a given IP address, hostname, or search Remove one or more entries based on a given IP address, hostname, or search
string. If an IP and hostname are both provided, only records matching the string. If an IP and hostname are both provided, only entries matching the
IP and hostname pair will be removed. IP and hostname pair will be removed.
Exit status: Exit status:
@ -1400,18 +1400,18 @@ remove() {
local _regex_hostname local _regex_hostname
_regex_hostname="^\\(..*[${_TAB_SPACE_}]${_search_string}\\)$" _regex_hostname="^\\(..*[${_TAB_SPACE_}]${_search_string}\\)$"
local _target_records local _target_entries
if ((_is_search_pair)) if ((_is_search_pair))
then then
_target_records=$( _target_entries=$(
sed -n \ sed -n \
-e "s/${_regex_ip_hostname_commented}/\\1/p" \ -e "s/${_regex_ip_hostname_commented}/\\1/p" \
-e "s/${_regex_ip_hostname}/\\1/p" \ -e "s/${_regex_ip_hostname}/\\1/p" \
"${HOSTS_PATH}" "${HOSTS_PATH}"
) )
else else
_target_records=$( _target_entries=$(
sed -n \ sed -n \
-e "s/${_regex_ip}/\\1/p" \ -e "s/${_regex_ip}/\\1/p" \
-e "s/${_regex_commented_hostname}/\\1/p" \ -e "s/${_regex_commented_hostname}/\\1/p" \
@ -1420,14 +1420,14 @@ remove() {
) )
fi fi
if [[ -z "${_target_records:-}" ]] if [[ -z "${_target_entries:-}" ]]
then then
_exit_1 printf "No matching records found.\\n" _exit_1 printf "No matching entries found.\\n"
fi fi
if ! ((_force_skip_prompt)) if ! ((_force_skip_prompt))
then then
printf "Removing the following records:\\n%s\\n" "${_target_records}" printf "Removing the following entries:\\n%s\\n" "${_target_entries}"
while true while true
do do
@ -1459,7 +1459,7 @@ remove() {
"${HOSTS_PATH}" "${HOSTS_PATH}"
fi fi
printf "Removed:\\n%s\\n" "${_target_records}" printf "Removed:\\n%s\\n" "${_target_entries}"
} }
desc "delete" "$(desc --get 'remove')" desc "delete" "$(desc --get 'remove')"
delete() { remove "${@}"; } delete() { remove "${@}"; }
@ -1504,30 +1504,30 @@ show() {
if [[ -n "${1:-}" ]] if [[ -n "${1:-}" ]]
then then
# Run `sed` before `grep` to avoid conflict that supresses `sed` output. # Run `sed` before `grep` to avoid conflict that supresses `sed` output.
local _disabled_records local _disabled_entries
_disabled_records="$( _disabled_entries="$(
sed -n "s/^\\#disabled: \\(.*${1}.*\\)$/\\1/p" "${HOSTS_PATH}" sed -n "s/^\\#disabled: \\(.*${1}.*\\)$/\\1/p" "${HOSTS_PATH}"
)" )"
local _enabled_records local _enabled_entries
_enabled_records="$( _enabled_entries="$(
grep --invert-match "^#" "${HOSTS_PATH}" | grep "${1}" || true grep --invert-match "^#" "${HOSTS_PATH}" | grep "${1}" || true
)" )"
if [[ -z "${_disabled_records}" ]] && if [[ -z "${_disabled_entries}" ]] &&
[[ -z "${_enabled_records}" ]] [[ -z "${_enabled_entries}" ]]
then then
_return_1 printf "No matching entries.\\n" _return_1 printf "No matching entries.\\n"
fi fi
_print_entries "${_enabled_records}" _print_entries "${_enabled_entries}"
if [[ -n "${_disabled_records}" ]] if [[ -n "${_disabled_entries}" ]]
then then
[[ -n "${_enabled_records}" ]] && printf "\\n" [[ -n "${_enabled_entries}" ]] && printf "\\n"
printf "Disabled:\\n" printf "Disabled:\\n"
printf "%s\\n" "---------" printf "%s\\n" "---------"
_print_entries "${_disabled_records}" _print_entries "${_disabled_entries}"
fi fi
else else
help show help show

View File

@ -18,7 +18,7 @@ load test_helper
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@test "\`disabled\` with no arguments prints list of disabled records." { @test "\`disabled\` with no arguments prints list of disabled entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net

View File

@ -18,7 +18,7 @@ load test_helper
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@test "\`enabled\` with no arguments prints list of enabled records." { @test "\`enabled\` with no arguments prints list of enabled entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net

View File

@ -53,7 +53,7 @@ load test_helper
run "${_HOSTS}" remove 127.0.0.3 --force run "${_HOSTS}" remove 127.0.0.3 --force
printf "\${status}: %s\\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${output} == "${_ERROR_PREFIX}No matching records found." ]] [[ ${output} == "${_ERROR_PREFIX}No matching entries found." ]]
} }
# `hosts remove <ip> --force` ################################################# # `hosts remove <ip> --force` #################################################

View File

@ -49,7 +49,7 @@ load test_helper
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@test "\`search enabled\` prints list of enabled records." { @test "\`search enabled\` prints list of enabled entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net
@ -95,7 +95,7 @@ load test_helper
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@test "\`search disabled\` prints list of disabled records." { @test "\`search disabled\` prints list of disabled entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net
@ -133,7 +133,7 @@ load test_helper
[[ ${status} -eq 0 ]] [[ ${status} -eq 0 ]]
} }
@test "\`search <search string>\` prints list of matching records." { @test "\`search <search string>\` prints list of matching entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net
@ -148,7 +148,7 @@ load test_helper
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
} }
@test "\`search <search string>\` prints records with matching comments." { @test "\`search <search string>\` prints entries with matching comments." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment" run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
@ -162,7 +162,7 @@ load test_helper
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
} }
@test "\`search <search string>\` prints disabled records with matching comments." { @test "\`search <search string>\` prints disabled entries with matching comments." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment" run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"

View File

@ -21,7 +21,7 @@ load test_helper
# `hosts show <no matching>` ################################################## # `hosts show <no matching>` ##################################################
@test "\`show <query>\` with no matching records with status 1." { @test "\`show <query>\` with no matching entries with status 1." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net
@ -77,7 +77,7 @@ load test_helper
# `hosts show <search string>` ################################################ # `hosts show <search string>` ################################################
@test "\`show <search string>\` exits with status 0 and shows matching records." { @test "\`show <search string>\` exits with status 0 and shows matching entries." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net run "${_HOSTS}" add 0.0.0.0 example.net
@ -94,7 +94,7 @@ load test_helper
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
} }
@test "\`show <search string>\` prints records with matching comments." { @test "\`show <search string>\` prints entries with matching comments." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment" run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
@ -109,7 +109,7 @@ load test_helper
[[ "${lines[2]}" == "" ]] [[ "${lines[2]}" == "" ]]
} }
@test "\`show <search string>\` prints disabled records with matching comments." { @test "\`show <search string>\` prints disabled entries with matching comments." {
{ {
run "${_HOSTS}" add 0.0.0.0 example.com run "${_HOSTS}" add 0.0.0.0 example.com
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment" run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"

View File

@ -49,7 +49,7 @@ load test_helper
run "${_HOSTS}" unblock example.net run "${_HOSTS}" unblock example.net
printf "\${status}: %s\\n" "${status}" printf "\${status}: %s\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}" printf "\${output}: '%s'\\n" "${output}"
[[ ${output} == "${_ERROR_PREFIX}No matching records found." ]] [[ ${output} == "${_ERROR_PREFIX}No matching entries found." ]]
} }
# `hosts unblock <hostname>` ################################################## # `hosts unblock <hostname>` ##################################################