ajout de semver_addmetadata
utiliser API moderne pour les perfs
This commit is contained in:
parent
ac940b819f
commit
8d3ab79b39
|
@ -14,12 +14,12 @@ function semver_parse() {
|
|||
local __p_ma="${2:-major}" __p_mi="${3:-minor}" __p_pl="${4:-patchlevel}"
|
||||
local __p_pr="${5:-prelease}" __p_md="${6:-metadata}" __p_va="${7:-valid}"
|
||||
local __p_tmp
|
||||
set_var "$__p_ma" ""
|
||||
set_var "$__p_mi" ""
|
||||
set_var "$__p_pl" ""
|
||||
setv "$__p_ma" ""
|
||||
setv "$__p_mi" ""
|
||||
setv "$__p_pl" ""
|
||||
array_new "$__p_pr"
|
||||
array_new "$__p_md"
|
||||
set_var "$__p_va" ""
|
||||
setv "$__p_va" ""
|
||||
|
||||
# vérifier les caractères valides
|
||||
__semver_check_version "$__p_ver" || return 1
|
||||
|
@ -32,7 +32,7 @@ function semver_parse() {
|
|||
done
|
||||
[ "${__p_ver:0:1}" == . ] || return 1
|
||||
__p_ver="${__p_ver:1}"
|
||||
set_var "$__p_ma" "$__p_tmp"
|
||||
setv "$__p_ma" "$__p_tmp"
|
||||
|
||||
# extraire minor
|
||||
__p_tmp=
|
||||
|
@ -42,7 +42,7 @@ function semver_parse() {
|
|||
done
|
||||
[ "${__p_ver:0:1}" == . ] || return 1
|
||||
__p_ver="${__p_ver:1}"
|
||||
set_var "$__p_mi" "$__p_tmp"
|
||||
setv "$__p_mi" "$__p_tmp"
|
||||
|
||||
# extraire patchlevel
|
||||
__p_tmp=
|
||||
|
@ -51,7 +51,7 @@ function semver_parse() {
|
|||
__p_ver="${__p_ver:1}"
|
||||
done
|
||||
[ -z "$__p_ver" -o "${__p_ver:0:1}" == - -o "${__p_ver:0:1}" == + ] || return 1
|
||||
set_var "$__p_pl" "$__p_tmp"
|
||||
setv "$__p_pl" "$__p_tmp"
|
||||
|
||||
# extraire prelease
|
||||
if [ "${__p_ver:0:1}" == - ]; then
|
||||
|
@ -79,25 +79,25 @@ function semver_parse() {
|
|||
# on doit avoir tout analysé
|
||||
[ -z "$__p_ver" ] || return 1
|
||||
|
||||
set_var "$__p_va" 1
|
||||
setv "$__p_va" 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function semver_incmajor() {
|
||||
set_var "$1" $((${!1} + 1))
|
||||
set_var "$2" 0
|
||||
set_var "$3" 0
|
||||
setv "$1" $((${!1} + 1))
|
||||
setv "$2" 0
|
||||
setv "$3" 0
|
||||
array_new "$4"
|
||||
}
|
||||
|
||||
function semver_incminor() {
|
||||
set_var "$2" $((${!2} + 1))
|
||||
set_var "$3" 0
|
||||
setv "$2" $((${!2} + 1))
|
||||
setv "$3" 0
|
||||
array_new "$4"
|
||||
}
|
||||
|
||||
function semver_incpatchlevel() {
|
||||
set_var "$3" $((${!3} + 1))
|
||||
setv "$3" $((${!3} + 1))
|
||||
array_new "$4"
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,9 @@ function semver_setversion() {
|
|||
local __sv_ma __sv_mi __sv_svl __sv_svr __sv_md __sv_va
|
||||
semver_parse "$1" __sv_ma __sv_mi __sv_pl __sv_pr __sv_md __sv_va
|
||||
[ -n "$__sv_va" ] || return 1
|
||||
set_var "$2" "$__sv_ma"
|
||||
set_var "$3" "$__sv_mi"
|
||||
set_var "$4" "$__sv_pl"
|
||||
setv "$2" "$__sv_ma"
|
||||
setv "$3" "$__sv_mi"
|
||||
setv "$4" "$__sv_pl"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -188,28 +188,38 @@ function semver_setmetadata() {
|
|||
return 0
|
||||
}
|
||||
|
||||
function semver_addmetadata() {
|
||||
if [ -n "$1" ]; then
|
||||
__semver_check_metadata "$1" || return 1
|
||||
local -a __sam_metadata
|
||||
array_split __sam_metadata "$1" .
|
||||
array_extend "$6" __sam_metadata
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function semver_compare_metadata() {
|
||||
# même algo que pour prelease
|
||||
semver_compare_prelease "$@"
|
||||
}
|
||||
|
||||
function semver_copy() {
|
||||
set_var "$1" "${!6}"
|
||||
set_var "$2" "${!7}"
|
||||
set_var "$3" "${!8}"
|
||||
setv "$1" "${!6}"
|
||||
setv "$2" "${!7}"
|
||||
setv "$3" "${!8}"
|
||||
array_copy "$4" "$9"
|
||||
array_copy "$5" "${10}"
|
||||
}
|
||||
|
||||
function semver_build() {
|
||||
echo_ "${!1}.${!2}.${!3}"
|
||||
array_isempty "$4" || rawecho_ "-$(array_join "$4" .)"
|
||||
array_isempty "$5" || rawecho_ "+$(array_join "$5" .)"
|
||||
array_isempty "$4" || recho_ "-$(array_join "$4" .)"
|
||||
array_isempty "$5" || recho_ "+$(array_join "$5" .)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
function semver_setvar() {
|
||||
set_var "$1" "$(semver_build "$2" "$3" "$4" "$5" "$6")"
|
||||
setv "$1" "$(semver_build "$2" "$3" "$4" "$5" "$6")"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
@ -225,6 +235,7 @@ function psemver_setversion() { semver_setversion "$1" "${2}major" "${2}minor" "
|
|||
function psemver_setprelease() { semver_setprelease "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||
function psemver_compare_prelease() { semver_compare_prelease "${1}prelease" "${2}prelease"; }
|
||||
function psemver_setmetadata() { semver_setmetadata "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||
function psemver_addmetadata() { semver_addmetadata "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||
function psemver_compare_metadata() { semver_compare_metadata "${1}metadata" "${2}metadata"; }
|
||||
function psemver_copy() { semver_copy "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||
function psemver_build() { semver_build "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
||||
|
|
Loading…
Reference in New Issue