dkbuild: ajout de from_glob()
This commit is contained in:
parent
2293239614
commit
027f9b8c45
28
dkbuild
28
dkbuild
|
@ -1108,6 +1108,34 @@ function load_environ() {
|
|||
eval "$(declare -p -x | sed -r 's/^declare -x ([^=]+)=/_ENVIRON[\1]=/')"
|
||||
}
|
||||
|
||||
function from_glob() {
|
||||
local var=value value
|
||||
[[ "$1" != *=* ]] && { var="$1"; shift; }
|
||||
|
||||
local path extract add_prefix add_suffix
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
path=*) path="${1#path=}";;
|
||||
extract=*) extract="${1#extract=}";;
|
||||
add-prefix=*) add_prefix="${1#add-prefix=}";;
|
||||
add-suffix=*) add_suffix="${1#add-suffix=}";;
|
||||
*=*) ewarn "path: $1: argument ignoré";;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
value="$(list_all . "$path" | sort -rn | head -1)"
|
||||
[ -n "$extract" ] || extract="${path//\*/(.*)}"
|
||||
if [ -n "$extract" ]; then
|
||||
extract="${extract//\//\\/}"
|
||||
value="$add_prefix$(awk -v version="$value" "BEGIN {
|
||||
if (match(version, /$extract/, vs)) { print vs[1] }
|
||||
else { print version }
|
||||
}")$add_suffix"
|
||||
fi
|
||||
|
||||
local "$var"; upvar "$var" "$value"
|
||||
}
|
||||
function define_functions_env() {
|
||||
function setversion() {
|
||||
[ -n "$SETVERSION_DONE" ] && return
|
||||
|
|
Loading…
Reference in New Issue