Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gitlab-com
migration
Commits
a3ea8367
Commit
a3ea8367
authored
Aug 02, 2018
by
Matteo Melli
Browse files
Menu ask now for function number and allow to quit or continue
parent
5357d167
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/database-wrangler/utilities
View file @
a3ea8367
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment