From 1a595da1bc2ffde582c7cc8d8a5afe156b4edea6 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Thu, 5 Mar 2015 10:12:00 +0400 Subject: [PATCH] =?UTF-8?q?-F=20permet=20de=20lire=20le=20contenu=20d'un?= =?UTF-8?q?=20fichier=20de=20version=20sans=20le=20mettre=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uversion | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/uversion b/uversion index 8f1cd1f..e19fa25 100755 --- a/uversion +++ b/uversion @@ -14,7 +14,10 @@ OPTIONS Gérer le numéro de version se trouvant dans le fichier spécifié. Le fichier est créé si nécessaire. C'est l'option par défaut si un fichier nommé VERSION.txt se trouve dans le répertoire courant. - -g, --git [branch:]VERSIONFILE + -F, --file-string VERSIONFILE + Prendre pour valeur de départ le contenu du fichier VERSIONFILE (qui + vaut par défaut VERSION.txt) + -g, --git-string [branch:]VERSIONFILE Prendre pour valeur de départ le contenu du fichier VERSIONFILE (qui vaut par défaut VERSION.txt) dans la branche BRANCH (qui vaut par défaut master) du dépôt git situé dans le répertoire courant. @@ -80,6 +83,8 @@ OPTIONS gestionnaire de version. Note: pour le moment, seul git est supporté." } +DEFAULT_FILE=VERSION.txt + action=auto source=auto file= @@ -100,8 +105,9 @@ vcsmetadata= parse_opts "${PRETTYOPTS[@]}" \ --help '$exit_with display_help' \ -f:,--file: '$set@ file; source=file' \ - -g:,--git: '$set@ git; source=git' \ - -s:,--string: '$set@ version; source=' \ + -F:,--file-string: '$set@ file; source=file-string' \ + -g:,--git-string: '$set@ git; source=git-string' \ + -s:,--string: '$set@ version; source=string' \ --show action=show \ --check action=check \ --convert convert=1 \ @@ -130,7 +136,7 @@ parse_opts "${PRETTYOPTS[@]}" \ # Calculer la source if [ "$source" == auto ]; then source=file - for i in VERSION.txt version.txt; do + for i in "$DEFAULT_FILE" version.txt; do if [ -f "$i" ]; then file="$i" break @@ -139,27 +145,35 @@ if [ "$source" == auto ]; then elif [ "$source" == file ]; then [ "$action" == auto ] && action=update fi -[ "$source" == file -a -z "$file" ] && file=VERSION.txt +[ "$source" == file -a -z "$file" ] && file="$DEFAULT_FILE" [ "$action" == auto ] && action=show # Lire la version if [ "$source" == file ]; then [ -f "$file" ] && version="$(<"$file")" - [ -n "$version" ] || version=0.0.0 -elif [ "$source" == git ]; then +elif [ "$source" == file-string ]; then + if [ -z "$file" ]; then + file="$DEFAULT_FILE" + elif [ -d "$file" ]; then + file="$file/$DEFAULT_FILE" + fi + [ -f "$file" ] && version="$(<"$file")" + file= +elif [ "$source" == git-string ]; then splitfsep2 "$git" : branch name [ -n "$branch" ] || branch=master - [ -n "$name" ] || name=VERSION.txt + [ -n "$name" ] || name="$DEFAULT_FILE" if git rev-parse --verify --quiet "$branch:$name" >/dev/null; then version="$(git cat-file blob "$branch:$name" 2>/dev/null)" fi - [ -n "$version" ] || version=0.0.0 fi +[ -n "$version" ] || version=0.0.0 # Conversion éventuelle du numéro de version psemver_parse "$version" +[ -n "$valid" ] && convert= if [ "$convert" == auto ]; then - [ -z "$valid" ] && convert=1 || convert= + [ -z "$valid" ] && convert=1 fi if [ -n "$convert" ]; then mversion="$(awkrun version="$version" ' @@ -201,7 +215,6 @@ BEGIN { fi # Actions - if [ "$action" == show ]; then if isatty; then estepi "La version actuelle est $version"