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

Use capitalized form of $_ME variable.

The capitalized version of this variable makes it easier to override,
even though this is not technically part of the external API. There is
no known downside of using the capitalized version of the variable.
This commit is contained in:
William Melody 2015-04-18 21:06:26 -07:00
parent e62bede843
commit cb9e20e554

82
hosts
View File

@ -245,12 +245,12 @@ _debug printf "\$command_parameters: %s\n" "${command_parameters[*]:-}"
# Environment # Environment
############################################################################### ###############################################################################
# $_me # $_ME
# #
# Set to the program's basename. # Set to the program's basename.
_me=$(basename "$0") _ME=$(basename "$0")
_debug printf "\$_me: %s\n" "$_me" _debug printf "\$_ME: %s\n" "$_ME"
############################################################################### ###############################################################################
# Load Commands # Load Commands
@ -475,7 +475,7 @@ _print_desc() {
desc version <<EOM desc version <<EOM
Usage: Usage:
$_me ( version | --version ) $_ME ( version | --version )
Description: Description:
Display the current program version. Display the current program version.
@ -490,10 +490,10 @@ version() {
desc help <<EOM desc help <<EOM
Usage: Usage:
$_me help [<command>] $_ME help [<command>]
Description: Description:
Display help information for $_me or a specified command. Display help information for $_ME or a specified command.
EOM EOM
help() { help() {
if [[ ${#command_argv[@]} = 1 ]]; then if [[ ${#command_argv[@]} = 1 ]]; then
@ -509,26 +509,26 @@ A program for managing host file entries.
Version: $_VERSION Version: $_VERSION
Usage: Usage:
$_me $_ME
$_me add <ip> <hostname> [comment] $_ME add <ip> <hostname> [comment]
$_me remove ( <ip> | <hostname> | <search string> ) [--force] $_ME remove ( <ip> | <hostname> | <search string> ) [--force]
$_me list [enabled | disabled | <search string>] $_ME list [enabled | disabled | <search string>]
$_me show ( <ip> | <hostname> | <search string> ) $_ME show ( <ip> | <hostname> | <search string> )
$_me disable ( <ip> | <hostname> | <search string> ) $_ME disable ( <ip> | <hostname> | <search string> )
$_me disabled $_ME disabled
$_me enable ( <ip> | <hostname> | <search string> ) $_ME enable ( <ip> | <hostname> | <search string> )
$_me enabled $_ME enabled
$_me edit $_ME edit
$_me file $_ME file
$_me -h | --help $_ME -h | --help
$_me --version $_ME --version
Options: Options:
-h --help Display this help information. -h --help Display this help information.
--version Display version information. --version Display version information.
Help: Help:
$_me help [<command>] $_ME help [<command>]
$(commands) $(commands)
EOM EOM
@ -541,7 +541,7 @@ EOM
desc commands <<EOM desc commands <<EOM
Usage: Usage:
$_me commands [--raw] $_ME commands [--raw]
Options: Options:
--raw Display the command list without formatting. --raw Display the command list without formatting.
@ -570,7 +570,7 @@ commands() {
# #
# desc example <<EOM # desc example <<EOM
# Usage: # Usage:
# $_me example # $_ME example
# #
# Description: # Description:
# Print "Hello, World!" # Print "Hello, World!"
@ -589,7 +589,7 @@ commands() {
desc add <<EOM desc add <<EOM
Usage: Usage:
$_me add <ip> <hostname> [comment] $_ME add <ip> <hostname> [comment]
Description: Description:
Add a given IP address and hostname pair, along with an optional comment. Add a given IP address and hostname pair, along with an optional comment.
@ -600,11 +600,11 @@ add() {
local hostname=${2:-} local hostname=${2:-}
local comment=${*:3} local comment=${*:3}
if [[ -z ${ip} ]]; then if [[ -z ${ip} ]]; then
$_me help add $_ME help add
exit 1 exit 1
elif [[ -z ${hostname} ]]; then elif [[ -z ${hostname} ]]; then
printf "Please include a hostname\n" printf "Please include a hostname\n"
$_me help add $_ME help add
exit 1 exit 1
elif grep \ elif grep \
-e "^${ip}\t${hostname}$" \ -e "^${ip}\t${hostname}$" \
@ -631,7 +631,7 @@ add() {
desc disable <<EOM desc disable <<EOM
Usage: 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 records based on a given ip address, hostname, or
@ -641,7 +641,7 @@ disable() {
_verify_write_permissions _verify_write_permissions
local search_term=$1 local search_term=$1
if [[ -z "${search_term}" ]]; then if [[ -z "${search_term}" ]]; then
$_me help disable $_ME help disable
exit 1 exit 1
else else
@ -656,20 +656,20 @@ disable() {
desc disabled <<EOM desc disabled <<EOM
Usage: Usage:
$_me disabled $_ME disabled
Description: Description:
List all disabled records. This is an alias for \`hosts list disabled\`. List all disabled records. This is an alias for \`hosts list disabled\`.
EOM EOM
disabled() { disabled() {
$_me list disabled $_ME list disabled
} }
# ------------------------------------------------------------------------ edit # ------------------------------------------------------------------------ edit
desc edit <<EOM desc edit <<EOM
Usage: Usage:
$_me edit $_ME edit
Description: Description:
Open the ${HOSTS_PATH} file in your \$EDITOR. Open the ${HOSTS_PATH} file in your \$EDITOR.
@ -687,7 +687,7 @@ edit() {
desc enable <<EOM desc enable <<EOM
Usage: 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 records based on a given ip address, hostname,
@ -697,7 +697,7 @@ enable() {
_verify_write_permissions _verify_write_permissions
local search_term=$1 local search_term=$1
if [[ -z "${search_term}" ]]; then if [[ -z "${search_term}" ]]; then
$_me help enable $_ME help enable
exit 1 exit 1
else else
target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/" target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/"
@ -713,20 +713,20 @@ enable() {
desc enabled <<EOM desc enabled <<EOM
Usage: Usage:
$_me enabled $_ME enabled
Description: Description:
List all enabled records. This is an alias for \`hosts list enabled\`. List all enabled records. This is an alias for \`hosts list enabled\`.
EOM EOM
enabled() { enabled() {
$_me list enabled $_ME list enabled
} }
# ------------------------------------------------------------------------ file # ------------------------------------------------------------------------ file
desc file <<EOM desc file <<EOM
Usage: Usage:
$_me file $_ME file
Description: Description:
Print the entire contents of the ${HOSTS_PATH} file. Print the entire contents of the ${HOSTS_PATH} file.
@ -739,7 +739,7 @@ file() {
desc list <<EOM desc list <<EOM
Usage: Usage:
$_me list [enabled | disabled | <search string>] $_ME list [enabled | disabled | <search string>]
Description: Description:
List the existing IP / hostname pairs, optionally limited to a specified List the existing IP / hostname pairs, optionally limited to a specified
@ -756,7 +756,7 @@ list() {
elif [[ "$1" == enabled ]]; then elif [[ "$1" == enabled ]]; then
grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}" grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}"
else else
$_me show "$1" $_ME show "$1"
fi fi
else else
# NOTE: use separate expressions since using a | for the or results in # NOTE: use separate expressions since using a | for the or results in
@ -772,7 +772,7 @@ list() {
desc remove <<EOM desc remove <<EOM
Usage: Usage:
$_me remove ( <ip> | <hostname> | <search string> ) [--force] $_ME remove ( <ip> | <hostname> | <search string> ) [--force]
Options: Options:
--force Skip the confirmation prompt. --force Skip the confirmation prompt.
@ -785,7 +785,7 @@ remove() {
_verify_write_permissions _verify_write_permissions
local search_string=${1:-} local search_string=${1:-}
if [[ -z $search_string ]]; then if [[ -z $search_string ]]; then
$_me help remove $_ME help remove
exit 1 exit 1
else else
local target_records=$(sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}") local target_records=$(sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}")
@ -820,7 +820,7 @@ remove() {
desc show <<EOM desc show <<EOM
Usage: Usage:
$_me show ( <ip> | <hostname> | <search string> ) $_ME show ( <ip> | <hostname> | <search string> )
Description: Description:
Print entries matching a given IP address, hostname, or search string. Print entries matching a given IP address, hostname, or search string.
@ -834,7 +834,7 @@ show() {
[[ -n "$enabled_records" ]] && printf "%s\n" "$enabled_records" [[ -n "$enabled_records" ]] && printf "%s\n" "$enabled_records"
[[ -n "$disabled_records" ]] && printf "%s\n" "$disabled_records" [[ -n "$disabled_records" ]] && printf "%s\n" "$disabled_records"
else else
$_me help show $_ME help show
exit 1 exit 1
fi fi
} }