add exact name match and leading name match checking

This commit is contained in:
fabolous005 2024-09-15 19:35:36 +02:00
parent f68f45999a
commit 8c728cf76a
2 changed files with 27 additions and 10 deletions

6
etools
View File

@ -66,17 +66,17 @@ function etools_unset() {
# INFO: einfo function
einfo() {
echo -e " ${ETOOLS_COLOR_INFO}*\033[0m $*"
echo -en "${ETOOLS_COLOR_INFO}*\033[0m $*" >&1
}
# INFO: ewarn function
ewarn() {
echo -e " ${ETOOLS_COLOR_WARN}* WARNING:\033[0m $*"
echo -en "${ETOOLS_COLOR_WARN}* WARNING:\033[0m $*" >&2
}
# INFO: eerror function
eerror() {
echo -e " ${ETOOLS_COLOR_ERROR}* ERROR:\033[0m $*"
echo -en "${ETOOLS_COLOR_ERROR}* ERROR:\033[0m $*" >&2
}

View File

@ -30,7 +30,7 @@ function _formatted_find() {
[ "$ETOOLS_DEBUG" = "true" ] && einfo "${ETOOLS_FIND_CMD}" "${2}" "$ETOOLS_FIND_ARGS" "${1}" >&2
fi
else
# TODO: do this with bash expansion only
# TODO: do this with bash variable expansion only
eval '$(echo "${ETOOLS_FIND_COMMAND//\{repo\}/${2}}" | sed -e "s/{package}/${1}/g")'
fi
}
@ -78,15 +78,32 @@ function _get_high() {
function _most_probable() {
(( $# == 2 )) && echo "${2//\"/}" && return 0;
# TODO: maybe don't just test trailing match, but rather excact package name first
# eg.: dev-util/devhelp < example/help
# check for exact name match
for package in "${@:2}"; do
# echo "$package"
if [[ ${package//\"/} == *"$1" ]]; then
echo "${package//\"/}" && return 0;
package=${package//\"/}
if [[ ${package#*/} == "$1" ]]; then
echo "$package" && return 0;
fi
done
# check for trailing name match
for package in "${@:2}"; do
package=${package//\"/}
if [[ $package == *"$1" ]]; then
echo "$package" && return 0;
fi
done
# check for leading name match
for package in "${@:2}"; do
package=${package//\"/}
if [[ $package == "$1"* ]]; then
echo "$package" && return 0;
fi
done
# TODO: maybe introduce another user function-call hook
# INFO: at this point we're lucky guessing
echo "${2//\"/}"
}
@ -116,7 +133,7 @@ function _debug_time() {
function _filter() {
# local start_time=$(date +%s%3N) && echo 0
# _debug_time "$start_time"
(( $# <= 1 )) && ewarn "No packages found, review config options" && return 1;
(( $# <= 0 )) && ewarn "No packages found, review config options" && return 1;
declare -Ag _etools_packages
for package in "$@"; do
package=${package//\"/}