mirror of https://github.com/octoleo/hosts.git
Fix `--force` behavior in `remove`.
The `--force` option is passed to the function in `$_COMMAND_ARGV`, which means that assigning arguments from positions in this array leads to unexpected behavior depending on where in the argument list `--force` is included. As a result, the `remove` function must parse the arguments, removing the `--force` argument before assigning function arguments to local variables. resolves #2
This commit is contained in:
parent
a869da8e4e
commit
09d6d83093
30
hosts
30
hosts
|
@ -945,6 +945,8 @@ EOM
|
||||||
remove() {
|
remove() {
|
||||||
_verify_write_permissions
|
_verify_write_permissions
|
||||||
local is_search_pair=0
|
local is_search_pair=0
|
||||||
|
local force_skip_prompt=0
|
||||||
|
local arguments=()
|
||||||
local search_ip=""
|
local search_ip=""
|
||||||
local search_hostname=""
|
local search_hostname=""
|
||||||
local search_string=""
|
local search_string=""
|
||||||
|
@ -952,18 +954,34 @@ remove() {
|
||||||
_debug printf "remove() \$1: %s\n" "${1:-}"
|
_debug printf "remove() \$1: %s\n" "${1:-}"
|
||||||
_debug printf "remove() \$2: %s\n" "${2:-}"
|
_debug printf "remove() \$2: %s\n" "${2:-}"
|
||||||
|
|
||||||
if [[ -z "${1:-}" ]]
|
for arg in "${_COMMAND_ARGV[@]:-}"
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
--force)
|
||||||
|
force_skip_prompt=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
arguments+=($arg)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
_debug printf "remove() \${arguments[0]}: %s\n" "${arguments[0]:-}"
|
||||||
|
_debug printf "remove() \${arguments[1]}: %s\n" "${arguments[1]:-}"
|
||||||
|
_debug printf "remove() \${arguments[2]}: %s\n" "${arguments[2]:-}"
|
||||||
|
|
||||||
|
if [[ -z "${arguments[1]:-}" ]]
|
||||||
then
|
then
|
||||||
$_ME help remove
|
$_ME help remove
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ -n "${2:-}" ]] && [[ ! "${2}" =~ ^-\* ]]
|
elif [[ -n "${arguments[2]:-}" ]]
|
||||||
then
|
then
|
||||||
search_ip="${1}"
|
search_ip="${arguments[1]}"
|
||||||
search_hostname="${2}"
|
search_hostname="${arguments[2]}"
|
||||||
is_search_pair=1
|
is_search_pair=1
|
||||||
_debug printf "remove() \$is_search_pair: %s\n" "$is_search_pair"
|
_debug printf "remove() \$is_search_pair: %s\n" "$is_search_pair"
|
||||||
else
|
else
|
||||||
search_string=${1:-}
|
search_string="${arguments[1]:-}"
|
||||||
_debug printf "remove() \$search_string: %s\n" "$search_string"
|
_debug printf "remove() \$search_string: %s\n" "$search_string"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1004,7 +1022,7 @@ remove() {
|
||||||
printf "No matching records found.\n"
|
printf "No matching records found.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! _command_argv_includes "--force"
|
if ! ((force_skip_prompt))
|
||||||
then
|
then
|
||||||
printf "Removing the following records:\n%s\n" "$target_records"
|
printf "Removing the following records:\n%s\n" "$target_records"
|
||||||
while true
|
while true
|
||||||
|
|
Loading…
Reference in New Issue