Skip to content

Commit

Permalink
Merge pull request #6 from NebzHB/beta
Browse files Browse the repository at this point in the history
Adding subStep for sub script that would want to have their own steps, please define those variables in your subscript (or by passing it as argument if you want a generic subscript for multiple plugins)

startSubStep= lower range of pourcentage your subscript will begin with (default 10)
stopSubStep= higher range of pourcentage your subscript will finish with (default 50)
numSubStepMax= max number of call to subStep you'll make in your subscript (to compute the percentage increment of each of your step) (default 9 -> 5% for each steps)
  • Loading branch information
NebzHB authored Apr 10, 2024
2 parents b2c8982 + 82083ff commit 978788a
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions dependance.lib
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,68 @@ step() {
echo $STEP_OK > $TMPFOLDER/step.$$
}

subStep() {
# Default values if not defined
[ -n "${startSubStep}" ] || startSubStep=10
[ -n "${stopSubStep}" ] || stopSubStep=50
[ -n "${numSubStepMax}" ] || numSubStepMax=9

# Compute pcIncrement only one time if necessary
if [ -z "${pcIncrement}" ]; then
pcIncrement=$(( (stopSubStep - startSubStep) / (numSubStepMax - 1) ))
if (( pcIncrement < 2 )); then
if [ "$LANG_DEP" = "fr" ]; then
echo "Avertissement Développeur: L'incrément de pourcentage par étape (${pcIncrement}%) est inférieur à 2%. Augmentez le range ou diminuez le nombre d'étapes."
else
echo "Developer Warning: The percentage increment per step (${pcIncrement}%) is less than 2%. Increase the range or reduce the number of steps"
fi
return
fi
fi

# Count how many time is called subStep in that sub script
if [ -z "${subStepCount}" ]; then
subStepCount=1
else
((subStepCount++))
fi

# Check if we don't call subStep more than numSubStepMax
if [ "$subStepCount" -gt "$numSubStepMax" ]; then
if [ "$LANG_DEP" = "fr" ]; then
echo "Avertissement Développeur: subStep appelée $subStepCount fois, mais numSubStepMax est défini à $numSubStepMax. Adaptez la valeur de numSubStepMax"
else
echo "Developer Warning: subStep has been called $subStepCount times, but you've defined numSubStepMax to $numSubStepMax. Please adapt numSubStepMax"
fi
return
fi

# Init pcInprog, then increment on each call
if [ -z "${pcInProg}" ]; then
pcInProg=$startSubStep
else
pcInProg=$((pcInProg + pcIncrement))
# don't go above stopSubStep
if [ "$pcInProg" -gt "$stopSubStep" ]; then
pcInProg=$stopSubStep
fi
fi

# Call step with pcInprog and any other arguments sent to subStep
step "$pcInProg" "$@"

# If the end of the steps is reached, reinit the variables
if [ "$pcInProg" -ge "$stopSubStep" ]; then
unset pcInProg
unset pcIncrement
unset startSubStep
unset stopSubStep
unset numSubStepMax
unset subStepCount
fi
}


try() {
cmdout="$("$@" 2>&1)"
local EXIT_CODE=$?
Expand Down

0 comments on commit 978788a

Please sign in to comment.