corriger l'implémentation de -v
n'afficher les message que si l'on a un tty implémenter semver_setversion
This commit is contained in:
parent
ac8cc8753d
commit
e10b3f09f3
105
ulib/semver
105
ulib/semver
|
@ -10,74 +10,76 @@ function __semver_check_prelease() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; }
|
||||||
function __semver_check_metadata() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; }
|
function __semver_check_metadata() { [ -z "${1//[a-zA-Z0-9.-]/}" ]; }
|
||||||
|
|
||||||
function semver_parse() {
|
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 __p_ver="$1"
|
||||||
local _tmp
|
local __p_ma="${2:-major}" __p_mi="${3:-minor}" __p_pl="${4:-patchlevel}"
|
||||||
set_var "$_ma" ""
|
local __p_pr="${5:-prelease}" __p_md="${6:-metadata}" __p_va="${7:-valid}"
|
||||||
set_var "$_mi" ""
|
local __p_tmp
|
||||||
set_var "$_pl" ""
|
set_var "$__p_ma" ""
|
||||||
array_new "$_pr"
|
set_var "$__p_mi" ""
|
||||||
array_new "$_md"
|
set_var "$__p_pl" ""
|
||||||
set_var "$_va" ""
|
array_new "$__p_pr"
|
||||||
|
array_new "$__p_md"
|
||||||
|
set_var "$__p_va" ""
|
||||||
|
|
||||||
# vérifier les caractères valides
|
# vérifier les caractères valides
|
||||||
__semver_check_version "$_ver" || return 1
|
__semver_check_version "$__p_ver" || return 1
|
||||||
|
|
||||||
# extraire major
|
# extraire major
|
||||||
_tmp=
|
__p_tmp=
|
||||||
while [ "${_ver/#[0-9]/}" != "$_ver" ]; do
|
while [ "${__p_ver/#[0-9]/}" != "$__p_ver" ]; do
|
||||||
_tmp="$_tmp${_ver:0:1}"
|
__p_tmp="$__p_tmp${__p_ver:0:1}"
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
done
|
done
|
||||||
[ "${_ver:0:1}" == . ] || return 1
|
[ "${__p_ver:0:1}" == . ] || return 1
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
set_var "$_ma" "$_tmp"
|
set_var "$__p_ma" "$__p_tmp"
|
||||||
|
|
||||||
# extraire minor
|
# extraire minor
|
||||||
_tmp=
|
__p_tmp=
|
||||||
while [ "${_ver/#[0-9]/}" != "$_ver" ]; do
|
while [ "${__p_ver/#[0-9]/}" != "$__p_ver" ]; do
|
||||||
_tmp="$_tmp${_ver:0:1}"
|
__p_tmp="$__p_tmp${__p_ver:0:1}"
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
done
|
done
|
||||||
[ "${_ver:0:1}" == . ] || return 1
|
[ "${__p_ver:0:1}" == . ] || return 1
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
set_var "$_mi" "$_tmp"
|
set_var "$__p_mi" "$__p_tmp"
|
||||||
|
|
||||||
# extraire patchlevel
|
# extraire patchlevel
|
||||||
_tmp=
|
__p_tmp=
|
||||||
while [ "${_ver/#[0-9]/}" != "$_ver" ]; do
|
while [ "${__p_ver/#[0-9]/}" != "$__p_ver" ]; do
|
||||||
_tmp="$_tmp${_ver:0:1}"
|
__p_tmp="$__p_tmp${__p_ver:0:1}"
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
done
|
done
|
||||||
[ -z "$_ver" -o "${_ver:0:1}" == - -o "${_ver:0:1}" == + ] || return 1
|
[ -z "$__p_ver" -o "${__p_ver:0:1}" == - -o "${__p_ver:0:1}" == + ] || return 1
|
||||||
set_var "$_pl" "$_tmp"
|
set_var "$__p_pl" "$__p_tmp"
|
||||||
|
|
||||||
# extraire prelease
|
# extraire prelease
|
||||||
if [ "${_ver:0:1}" == - ]; then
|
if [ "${__p_ver:0:1}" == - ]; then
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
if [[ "$_ver" == *+* ]]; then
|
if [[ "$__p_ver" == *+* ]]; then
|
||||||
_tmp="${_ver%%+*}"
|
__p_tmp="${__p_ver%%+*}"
|
||||||
_ver="+${_ver##*+}"
|
__p_ver="+${__p_ver##*+}"
|
||||||
else
|
else
|
||||||
_tmp="$_ver"
|
__p_tmp="$__p_ver"
|
||||||
_ver=
|
__p_ver=
|
||||||
fi
|
fi
|
||||||
__semver_check_prelease "$_tmp" || return 1
|
__semver_check_prelease "$__p_tmp" || return 1
|
||||||
array_split "$_pr" "$_tmp" .
|
array_split "$__p_pr" "$__p_tmp" .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# extraire metadata
|
# extraire metadata
|
||||||
if [ "${_ver:0:1}" == + ]; then
|
if [ "${__p_ver:0:1}" == + ]; then
|
||||||
_ver="${_ver:1}"
|
__p_ver="${__p_ver:1}"
|
||||||
_tmp="$_ver"
|
__p_tmp="$__p_ver"
|
||||||
_ver=
|
__p_ver=
|
||||||
__semver_check_metadata "$_tmp" || return 1
|
__semver_check_metadata "$__p_tmp" || return 1
|
||||||
array_split "$_md" "$_tmp" .
|
array_split "$__p_md" "$__p_tmp" .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# on doit avoir tout analysé
|
# on doit avoir tout analysé
|
||||||
[ -z "$_ver" ] || return 1
|
[ -z "$__p_ver" ] || return 1
|
||||||
|
|
||||||
set_var "$_va" 1
|
set_var "$__p_va" 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +101,16 @@ function semver_incpatchlevel() {
|
||||||
array_new "$4"
|
array_new "$4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
function semver_setprelease() {
|
function semver_setprelease() {
|
||||||
# XXX analyser $1 et spliter avant de copier dans le tableau $5
|
# XXX analyser $1 et spliter avant de copier dans le tableau $5
|
||||||
if [ "$1" ]; then
|
if [ "$1" ]; then
|
||||||
|
@ -153,6 +165,7 @@ function psemver_parse() { semver_parse "$1" "${2}major" "${2}minor" "${2}patchl
|
||||||
function psemver_incmajor() { semver_incmajor "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
function psemver_incmajor() { semver_incmajor "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
||||||
function psemver_incminor() { semver_incminor "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
function psemver_incminor() { semver_incminor "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
||||||
function psemver_incpatchlevel() { semver_incpatchlevel "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
function psemver_incpatchlevel() { semver_incpatchlevel "${1}major" "${1}minor" "${1}patchlevel" "${1}prelease" "${1}metadata"; }
|
||||||
|
function psemver_setversion() { semver_setversion "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||||
function psemver_setprelease() { semver_setprelease "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
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_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_setmetadata() { semver_setmetadata "$1" "${2}major" "${2}minor" "${2}patchlevel" "${2}prelease" "${2}metadata"; }
|
||||||
|
|
30
uversion
30
uversion
|
@ -137,17 +137,14 @@ fi
|
||||||
# Actions
|
# Actions
|
||||||
|
|
||||||
if [ "$action" == show ]; then
|
if [ "$action" == show ]; then
|
||||||
estepi "La version actuelle est $version"
|
if isatty; then
|
||||||
|
estepi "La version actuelle est $version"
|
||||||
|
else
|
||||||
|
echo "$version"
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# forcer le numéro de version
|
|
||||||
# XXX implémenter semver_setversion qui change juste la partie
|
|
||||||
# major.minor.patchlevel et ne touche pas au reste. une fois que cela sera fait,
|
|
||||||
# la ligne suivante doit être supprimée et le code de setversion doit être
|
|
||||||
# mis dans la partie "update"
|
|
||||||
[ -n "$setversion" ] && version="$setversion"
|
|
||||||
|
|
||||||
psemver_parse "$version"
|
psemver_parse "$version"
|
||||||
if [ "$action" == check ]; then
|
if [ "$action" == check ]; then
|
||||||
[ -n "$valid" ] || die "Numéro de version invalide: $version"
|
[ -n "$valid" ] || die "Numéro de version invalide: $version"
|
||||||
|
@ -236,12 +233,19 @@ elif [ "$action" == update ]; then
|
||||||
|
|
||||||
if [ -n "$file" ]; then
|
if [ -n "$file" ]; then
|
||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
estepi "La version actuelle est $version"
|
if isatty; then
|
||||||
|
estepi "La version actuelle est $version"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
ask_yesno "Le fichier $(ppath "$file") n'existe pas. Faut-il le créer?" O || die
|
if isatty; then
|
||||||
|
ask_yesno "Le fichier $(ppath "$file") n'existe pas. Faut-il le créer?" O || die
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# forcer le numéro de version
|
||||||
|
psemver_setversion "$setversion" "" || die "Numéro de version invalide: $setversion"
|
||||||
|
|
||||||
# incrémenter les numéros de version
|
# incrémenter les numéros de version
|
||||||
if [ "$incversion" == auto ]; then
|
if [ "$incversion" == auto ]; then
|
||||||
if [ -n "$setrelease" -o -n "$setprelease" -o -n "$setmetadata" ]; then
|
if [ -n "$setrelease" -o -n "$setprelease" -o -n "$setmetadata" ]; then
|
||||||
|
@ -299,7 +303,11 @@ elif [ "$action" == update ]; then
|
||||||
if [ -n "$file" ]; then
|
if [ -n "$file" ]; then
|
||||||
echo "$version" >"$file"
|
echo "$version" >"$file"
|
||||||
fi
|
fi
|
||||||
estepn "La nouvelle version est $version"
|
if isatty; then
|
||||||
|
estepn "La nouvelle version est $version"
|
||||||
|
else
|
||||||
|
echo "$version"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue