-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_exercise.sh
executable file
·65 lines (56 loc) · 1.13 KB
/
create_exercise.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
IFS='
'
cd -P "$(dirname "$0")"
NC="\033[0m"
WHT="\033[0;37m"
BLK="\033[0;30m"
RED="\033[0;31m"
YEL="\033[0;33m"
BLU="\033[0;34m"
GRN="\033[0;32m"
ARG=$1
IS_LIB=false
create_exercise () {
exercise=$1
exercise_test=${exercise}"_test"
if [[ $IS_LIB == true ]]
then
solution_args="--lib"
fi
cd solutions
cargo new $solution_args $exercise
cd ../tests
cargo new $exercise_test
if [[ $IS_LIB == true ]]
then
echo "$exercise = { path = \"../../solutions/${exercise}\" }" >> ${exercise_test}/Cargo.toml
fi
cd ..
}
if [ -n $ARG ] && ([[ $ARG == '-h' ]] || [[ $ARG == '--help' ]])
then
echo "Create new exercises boilerplates for Rust
-h, --help show this usage screen
-l add `--lib` as argument to cargo new
[exercise_name] create one or more exercises (separated by spaces)"
else
# Arguments parsing
while [[ $# -gt 0 ]]
do
case $1 in
-l)
IS_LIB=true
shift
;;
*)
break
esac
done
while [[ $# -gt 0 ]]
do
exercise="${1}"
create_exercise $exercise
shift # past argument
done
fi