forked from cucumber-school/student
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcucumber-school
More file actions
executable file
·122 lines (106 loc) · 3.4 KB
/
cucumber-school
File metadata and controls
executable file
·122 lines (106 loc) · 3.4 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
GREEN='\033[0;32m'
NO_COLOR='\033[0m'
echo -e "$GREEN"
cat << 'BANNER'
______ __ _____ __ __
/ ____/_ _________ ______ ___ / /_ ___ _____ / ___/_____/ /_ ____ ____ / /
/ / / / / / ___/ / / / __ `__ \/ __ \/ _ \/ ___/ \__ \/ ___/ __ \/ __ \/ __ \/ /
/ /___/ /_/ / /__/ /_/ / / / / / / /_/ / __/ / ___/ / /__/ / / / /_/ / /_/ / /
\____/\__,_/\___/\__,_/_/ /_/ /_/_.___/\___/_/ /____/\___/_/ /_/\____/\____/_/
BANNER
cat << INTRO
This tool will set you up ready to follow along with the conding examples from the Cucumber School video series.
We keep all the code for the videos in git, we're going to get you to the starting-point for
any chapter in the series, so you can follow along on your own machine.
It will create a folder below $(pwd) so make sure you're in the right directory before you start.
INTRO
echo -e "$NO_COLOR"
while [[ $# -gt 0 ]]; do
case $1 in
clone)
COMMAND=$1
echo "command: $COMMAND"
shift
;;
-l | --language)
LANGUAGE=$2
echo "lang: $LANGUAGE"
shift
shift
;;
-c | --chapter)
CHAPTER=$2
echo "chapter: $CHAPTER"
shift
shift
;;
-d | --directory)
DIRECTORY=$2
echo "directory: $DIRECTORY"
shift
shift
;;
-h | --help)
echo "cucumber-school: Student tourguide to the code examples"
show_usage
exit 0
;;
--* | -*)
echo "Unknown option $1"
show_usage
exit 1
;;
esac
done
# No point in forcing the user to choose this one yet
COURSE=bdd-with-cucumber
if [ -z "$LANGUAGE" ]; then
echo "Please choose a language:"
select LANGUAGE in "java" "ruby" "js"
do
[ -n "$LANGUAGE" ] && break
done
fi
function lookup_chapters() {
git ls-remote git@github.com:cucumber-school/scripts | grep refs/heads/code.$COURSE | grep .$LANGUAGE | grep -v .start$ | cut -d '.' -f 3 | uniq
}
if [ -z "$CHAPTER" ]; then
chapters="$(lookup_chapters $LANGUAGE)"
echo
echo "Please choose a chapter:"
select CHAPTER in $chapters
do
[ -n "$CHAPTER" ] && break
done
fi
if [ -z "$DIRECTORY" ]; then
default=$COURSE.$CHAPTER.$LANGUAGE
echo
read -r -p "Where do you want to clone the code? [$default]" DIRECTORY
DIRECTORY=${DIRECTORY:-$default}
fi
if [ -d "$DIRECTORY" ]; then
echo "$DIRECTORY already exists!"
echo "Please delete that directory or choose a different destination."
exit 1
fi
start_point_branch="code.bdd-with-cucumber.$CHAPTER.$LANGUAGE.start"
end_point_branch="code.bdd-with-cucumber.$CHAPTER.$LANGUAGE"
printf "Cloning code branch into %s..." "$DIRECTORY"
git clone --quiet --single-branch --branch "$start_point_branch" git@github.com:cucumber-school/scripts "$DIRECTORY"
git -C "$DIRECTORY" branch --quiet --move "$start_point_branch" start
git -C "$DIRECTORY" fetch --quiet git@github.com:cucumber-school/scripts "$end_point_branch:answers"
printf "Done\n"
echo -e "$GREEN"
echo "The start-point for the code from chapter $CHAPTER of $COURSE ($LANGUAGE) has been cloned into $DIRECTORY"
echo
echo "That directory is a little git repo which also has an 'answers' branch where you can see the code we used in the videos."
echo
echo "Try running this command to see all the commits we used in the videos:"
echo " git log --reverse answers"
echo
echo "Moving you into that directory so you can get started right away. Have fun!"
echo -e "$NO_COLOR"
cd "$DIRECTORY" || exit 1
$SHELL || exit 0