-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
add-exercise
executable file
·57 lines (41 loc) · 1.72 KB
/
add-exercise
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
#!/usr/bin/env bash
set -euo pipefail
if (( $# != 1 )); then
echo >&2 "Populates a new directory for a practice exercise."
echo >&2 "Usage: $0 <exercise-slug>"
exit 1
fi
die() { echo >&2 "$*"; exit 1; }
required_tool() {
command -v "$1" >/dev/null 2>&1 ||
die "$1 is required but not installed. Please install it and make sure it's in your PATH."
}
required_tool jq
[[ -f ./bin/fetch-configlet ]] || die "run this script from the repo's root directory."
slug="${1}"
it_exists=$(
jq --arg slug "${slug}" '
.exercises.practice
| map(select(.slug == $slug))
| length > 0
' config.json
)
[[ ${it_exists} == false ]] || die "${slug} already exists in config.json"
./bin/fetch-configlet || die "cannot fetch configlet"
read -rp 'Your github username: ' author
./bin/configlet create --practice-exercise "${slug}" --author "${author}"
echo '"Remove this line and implement your solution" | halt_error' > "exercises/practice/${slug}/${slug}.jq"
cp -pt exercises/practice/"${slug}" lib/bats-*.bash
./bin/generate_tests "${slug}" || true
echo
find "exercises/practice/${slug}" -type f -ls
cat << NEXT_STEPS
Your next steps are:
- Review the test suite in 'exercises/practice/${slug}/test-${slug}.jq'
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
- Create the example solution in 'exercises/practice/${slug}/.meta/example.jq'
- Verify the example solution by running 'bin/validate_one_exercise exercises/practice/${slug}'
- Review the stub solution in 'exercises/practice/${slug}/${slug}.jq'
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file
- Validate CI using 'bin/configlet lint'
NEXT_STEPS