mirror of https://github.com/octoleo/hosts.git
Use `HEREDOC` rather than `EOM` to define heredocs.
This commit is contained in:
parent
f4ebb9468a
commit
4194b25459
68
hosts
68
hosts
|
@ -510,9 +510,9 @@ sudo !!\n"
|
||||||
# implementation and simplicity. There is an alternative assignment form
|
# implementation and simplicity. There is an alternative assignment form
|
||||||
# that could be used here:
|
# that could be used here:
|
||||||
#
|
#
|
||||||
# var="$(cat <<'EOM'
|
# var="$(cat <<'HEREDOC'
|
||||||
# some message
|
# some message
|
||||||
# EOM
|
# HEREDOC
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# However, this form appears to require trailing space after backslases to
|
# However, this form appears to require trailing space after backslases to
|
||||||
|
@ -523,9 +523,9 @@ desc() {
|
||||||
[[ -z ${1} ]] && _die printf "desc: No command name specified.\n"
|
[[ -z ${1} ]] && _die printf "desc: No command name specified.\n"
|
||||||
if [[ -n ${2:-} ]]
|
if [[ -n ${2:-} ]]
|
||||||
then
|
then
|
||||||
read -d '' "_desc_${1}" <<EOM
|
read -d '' "_desc_${1}" <<HEREDOC
|
||||||
${2}
|
${2}
|
||||||
EOM
|
HEREDOC
|
||||||
_debug printf "desc() set with argument: _desc_%s\n" "${1}"
|
_debug printf "desc() set with argument: _desc_%s\n" "${1}"
|
||||||
else
|
else
|
||||||
read -d '' "_desc_${1}"
|
read -d '' "_desc_${1}"
|
||||||
|
@ -557,7 +557,7 @@ _print_desc() {
|
||||||
|
|
||||||
# Version #####################################################################
|
# Version #####################################################################
|
||||||
|
|
||||||
desc "version" <<EOM
|
desc "version" <<HEREDOC
|
||||||
Usage:
|
Usage:
|
||||||
${_ME} (version | --version)
|
${_ME} (version | --version)
|
||||||
|
|
||||||
|
@ -565,24 +565,24 @@ Description:
|
||||||
Display the current program version.
|
Display the current program version.
|
||||||
|
|
||||||
To save you the trouble, the current version is ${_VERSION}
|
To save you the trouble, the current version is ${_VERSION}
|
||||||
EOM
|
HEREDOC
|
||||||
version() {
|
version() {
|
||||||
printf "%s\n" "${_VERSION}"
|
printf "%s\n" "${_VERSION}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Help ########################################################################
|
# Help ########################################################################
|
||||||
|
|
||||||
desc "help" <<EOM
|
desc "help" <<HEREDOC
|
||||||
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
|
HEREDOC
|
||||||
help() {
|
help() {
|
||||||
if [[ ${#_COMMAND_ARGV[@]} = 1 ]]
|
if [[ ${#_COMMAND_ARGV[@]} = 1 ]]
|
||||||
then
|
then
|
||||||
cat <<EOM
|
cat <<HEREDOC
|
||||||
__ __
|
__ __
|
||||||
/ /_ ____ _____/ /______
|
/ /_ ____ _____/ /______
|
||||||
/ __ \/ __ \/ ___/ __/ ___/
|
/ __ \/ __ \/ ___/ __/ ___/
|
||||||
|
@ -616,7 +616,7 @@ Help:
|
||||||
${_ME} help [<command>]
|
${_ME} help [<command>]
|
||||||
|
|
||||||
$(commands)
|
$(commands)
|
||||||
EOM
|
HEREDOC
|
||||||
else
|
else
|
||||||
_print_desc "${1}"
|
_print_desc "${1}"
|
||||||
fi
|
fi
|
||||||
|
@ -624,7 +624,7 @@ EOM
|
||||||
|
|
||||||
# Command List ################################################################
|
# Command List ################################################################
|
||||||
|
|
||||||
desc "commands" <<EOM
|
desc "commands" <<HEREDOC
|
||||||
Usage:
|
Usage:
|
||||||
${_ME} commands [--raw]
|
${_ME} commands [--raw]
|
||||||
|
|
||||||
|
@ -633,7 +633,7 @@ Options:
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Display the list of available commands.
|
Display the list of available commands.
|
||||||
EOM
|
HEREDOC
|
||||||
commands() {
|
commands() {
|
||||||
if _command_argv_includes "--raw"
|
if _command_argv_includes "--raw"
|
||||||
then
|
then
|
||||||
|
@ -654,7 +654,7 @@ commands() {
|
||||||
# example() { : } - The command called by the user.
|
# example() { : } - The command called by the user.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# desc example <<EOM
|
# desc example <<HEREDOC
|
||||||
# Usage:
|
# Usage:
|
||||||
# $_ME example
|
# $_ME example
|
||||||
#
|
#
|
||||||
|
@ -664,7 +664,7 @@ commands() {
|
||||||
# For usage formatting conventions see:
|
# For usage formatting conventions see:
|
||||||
# - http://docopt.org/
|
# - http://docopt.org/
|
||||||
# - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
# - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
||||||
# EOM
|
# HEREDOC
|
||||||
# example() {
|
# example() {
|
||||||
# printf "Hello, World!\n"
|
# printf "Hello, World!\n"
|
||||||
# }
|
# }
|
||||||
|
@ -673,13 +673,13 @@ commands() {
|
||||||
|
|
||||||
# ------------------------------------------------------------------------- add
|
# ------------------------------------------------------------------------- add
|
||||||
|
|
||||||
desc "add" <<EOM
|
desc "add" <<HEREDOC
|
||||||
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.
|
||||||
EOM
|
HEREDOC
|
||||||
add() {
|
add() {
|
||||||
_debug printf "add() \${1}: %s\n" "${1:-}"
|
_debug printf "add() \${1}: %s\n" "${1:-}"
|
||||||
_debug printf "add() \${2}: %s\n" "${2:-}"
|
_debug printf "add() \${2}: %s\n" "${2:-}"
|
||||||
|
@ -731,14 +731,14 @@ add() {
|
||||||
|
|
||||||
# --------------------------------------------------------------------- disable
|
# --------------------------------------------------------------------- disable
|
||||||
|
|
||||||
desc "disable" <<EOM
|
desc "disable" <<HEREDOC
|
||||||
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
|
||||||
search string.
|
search string.
|
||||||
EOM
|
HEREDOC
|
||||||
disable() {
|
disable() {
|
||||||
_verify_write_permissions
|
_verify_write_permissions
|
||||||
local search_string="${1}"
|
local search_string="${1}"
|
||||||
|
@ -785,26 +785,26 @@ disable() {
|
||||||
|
|
||||||
# -------------------------------------------------------------------- disabled
|
# -------------------------------------------------------------------- disabled
|
||||||
|
|
||||||
desc "disabled" <<EOM
|
desc "disabled" <<HEREDOC
|
||||||
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
|
HEREDOC
|
||||||
disabled() {
|
disabled() {
|
||||||
${_ME} list disabled
|
${_ME} list disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ edit
|
# ------------------------------------------------------------------------ edit
|
||||||
|
|
||||||
desc "edit" <<EOM
|
desc "edit" <<HEREDOC
|
||||||
Usage:
|
Usage:
|
||||||
${_ME} edit
|
${_ME} edit
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Open the ${HOSTS_PATH} file in your \$EDITOR.
|
Open the ${HOSTS_PATH} file in your \$EDITOR.
|
||||||
EOM
|
HEREDOC
|
||||||
edit() {
|
edit() {
|
||||||
_verify_write_permissions
|
_verify_write_permissions
|
||||||
if [[ -z "${EDITOR}" ]]
|
if [[ -z "${EDITOR}" ]]
|
||||||
|
@ -817,14 +817,14 @@ edit() {
|
||||||
|
|
||||||
# ---------------------------------------------------------------------- enable
|
# ---------------------------------------------------------------------- enable
|
||||||
|
|
||||||
desc "enable" <<EOM
|
desc "enable" <<HEREDOC
|
||||||
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,
|
||||||
or search string.
|
or search string.
|
||||||
EOM
|
HEREDOC
|
||||||
enable() {
|
enable() {
|
||||||
_verify_write_permissions
|
_verify_write_permissions
|
||||||
local search_string="${1}"
|
local search_string="${1}"
|
||||||
|
@ -871,33 +871,33 @@ enable() {
|
||||||
|
|
||||||
# --------------------------------------------------------------------- enabled
|
# --------------------------------------------------------------------- enabled
|
||||||
|
|
||||||
desc "enabled" <<EOM
|
desc "enabled" <<HEREDOC
|
||||||
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
|
HEREDOC
|
||||||
enabled() {
|
enabled() {
|
||||||
${_ME} list enabled
|
${_ME} list enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ file
|
# ------------------------------------------------------------------------ file
|
||||||
|
|
||||||
desc "file" <<EOM
|
desc "file" <<HEREDOC
|
||||||
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.
|
||||||
EOM
|
HEREDOC
|
||||||
file() {
|
file() {
|
||||||
cat "${HOSTS_PATH}"
|
cat "${HOSTS_PATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ list
|
# ------------------------------------------------------------------------ list
|
||||||
|
|
||||||
desc "list" <<EOM
|
desc "list" <<HEREDOC
|
||||||
Usage:
|
Usage:
|
||||||
${_ME} list [enabled | disabled | <search string>]
|
${_ME} list [enabled | disabled | <search string>]
|
||||||
|
|
||||||
|
@ -905,7 +905,7 @@ 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 records will
|
||||||
be printed.
|
be printed.
|
||||||
EOM
|
HEREDOC
|
||||||
list() {
|
list() {
|
||||||
# Get the disabled records up front for the two cases where they are needed.
|
# Get the disabled records up front for the two cases where they are needed.
|
||||||
local disabled_records
|
local disabled_records
|
||||||
|
@ -937,7 +937,7 @@ list() {
|
||||||
|
|
||||||
# ---------------------------------------------------------------------- remove
|
# ---------------------------------------------------------------------- remove
|
||||||
|
|
||||||
desc "remove" <<EOM
|
desc "remove" <<HEREDOC
|
||||||
Usage:
|
Usage:
|
||||||
${_ME} remove (<ip> | <hostname> | <search string>) [--force]
|
${_ME} remove (<ip> | <hostname> | <search string>) [--force]
|
||||||
${_ME} remove <ip> <hostname>
|
${_ME} remove <ip> <hostname>
|
||||||
|
@ -949,7 +949,7 @@ Description:
|
||||||
Remove one or more records based on a given IP address, hostname, or search
|
Remove one or more records 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 records matching the
|
||||||
IP and hostname pair will be removed.
|
IP and hostname pair will be removed.
|
||||||
EOM
|
HEREDOC
|
||||||
remove() {
|
remove() {
|
||||||
_verify_write_permissions
|
_verify_write_permissions
|
||||||
local is_search_pair=0
|
local is_search_pair=0
|
||||||
|
@ -1072,13 +1072,13 @@ remove() {
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ show
|
# ------------------------------------------------------------------------ show
|
||||||
|
|
||||||
desc "show" <<EOM
|
desc "show" <<HEREDOC
|
||||||
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.
|
||||||
EOM
|
HEREDOC
|
||||||
show() {
|
show() {
|
||||||
if [[ -n "${1}" ]]
|
if [[ -n "${1}" ]]
|
||||||
then
|
then
|
||||||
|
|
Loading…
Reference in New Issue