fonctions de vérification
This commit is contained in:
parent
ea0f428ebe
commit
5388951acb
|
@ -5,6 +5,10 @@
|
|||
uprovide semver
|
||||
urequire base
|
||||
|
||||
function __semver_check_version() { [ -z "${1//[a-zA-Z0-9.+-]/}" ]; }
|
||||
function __semver_check_prelease() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; }
|
||||
function __semver_check_metadata() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; }
|
||||
|
||||
function semver_parse() {
|
||||
local _ver="$1" _ma="${2:-major}" _mi="${3:-minor}" _pl="${4:-patchlevel}" _pr="${5:-prelease}" _md="${6:-metadata}" _va="${7:-valid}"
|
||||
local _tmp
|
||||
|
@ -16,7 +20,7 @@ function semver_parse() {
|
|||
set_var "$_va" ""
|
||||
|
||||
# vérifier les caractères valides
|
||||
[ -z "${_ver//[a-zA-Z0-9.+-]/}" ] || return 1
|
||||
__semver_check_version "$_ver" || return 1
|
||||
|
||||
# extraire major
|
||||
_tmp=
|
||||
|
@ -57,15 +61,16 @@ function semver_parse() {
|
|||
_tmp="$_ver"
|
||||
_ver=
|
||||
fi
|
||||
__semver_check_prelease "$_tmp" || return 1
|
||||
array_split "$_pr" "$_tmp" .
|
||||
fi
|
||||
|
||||
# extraire metadata
|
||||
if [ "${_ver:0:1}" == + ]; then
|
||||
_ver="${_ver:1}"
|
||||
[[ "$_ver" == *+* ]] && return 1
|
||||
_tmp="$_ver"
|
||||
_ver=
|
||||
__semver_check_metadata "$_tmp" || return 1
|
||||
array_split "$_md" "$_tmp" .
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue