Commit a3ea8367 authored by Matteo Melli's avatar Matteo Melli
Browse files

Menu ask now for function number and allow to quit or continue

parent 5357d167
......@@ -7,17 +7,100 @@ function do_step(){
}
function step_3digit_number(){
echo "$1"|cut -d _ -f 1
}
function step_number(){
printf "%d" "$(step_3digit_number "$1"|sed 's/0\+//')"
}
function step_name(){
echo "$1"|cut -d _ -f 2-
}
function has_step(){
found=false
for step in "${steps[@]}"
do
if [ "$(step_3digit_number "$step")" == "$1" ]
then
found=true
break;
fi
done
$found
}
function do_menu(){
select step in "${steps[@]}"
next_step="$(step_3digit_number "${steps[0]}")"
while true
do
echo "Step $step will be executed:"
echo "Available steps:"
echo
type "$step" | head -n -1 | tail -n +4
for step in "${steps[@]}"
do
echo "$(step_3digit_number "$step")) $(step_name "$step")"
done
echo
read -s -N 1 -p "Press [y] to continue, any other key to abort." key
if [ "$key" == "y" ]
if has_step "$next_step"
then
export read_prompt="Enter the step number to execute, next to execute step $next_step or quit to exit? "
else
export read_prompt="Enter the step number to execute or quit to exit? "
fi
command="$(rlwrap -C migration bash -c 'read -p "$read_prompt" command; echo "$command"')"
step=
case "$command" in
quit)
exit 0
;;
next)
found=false
for step in "${steps[@]}"
do
if [ "$(step_3digit_number "$step")" == "$next_step" ]
then
found=true
break;
fi
done
if ! $found
then
step=
fi
;;
[0-9][0-9][0-9])
found=false
for step in "${steps[@]}"
do
if [ "$(step_3digit_number "$step")" == "$command" ]
then
found=true
break;
fi
done
if ! $found
then
echo "Sorry, no step $command found! Please enter all step digits."
step=
fi
;;
esac
if [ ! -z "$step" ]
then
do_step "$step"
echo "Step $step will be executed:"
echo
type "$step" | head -n -1 | tail -n +4
echo
read -s -N 1 -p "Press [y] to continue, any other key to abort." key
if [ "$key" == "y" ]
then
next_step="$(printf "%03d" "$(($(step_number "$step")+1))")"
do_step "$step"
fi
echo
step=
fi
done
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment