Skip to content

Commit 00d2b92

Browse files
committed
Break out canonical data fetching
1 parent 877dc7a commit 00d2b92

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "Usage: bin/generator-utils/fetch_canonical_data <exercise-slug>"
5+
exit 1
6+
fi
7+
8+
# check if curl is installed
9+
command -v curl >/dev/null 2>&1 || {
10+
echo >&2 "curl is required but not installed. Please install it and make sure it's in your PATH."
11+
exit 1
12+
}
13+
14+
slug=$1
15+
16+
curlopts=(
17+
--silent
18+
--show-error
19+
--fail
20+
--location
21+
--retry 3
22+
--max-time 4
23+
)
24+
curl "${curlopts[@]}" "https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/${slug}/canonical-data.json"

bin/generator-utils/templates.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,8 @@ use $(dash_to_underscore "$slug")::*;
1414
1515
EOT
1616

17-
curlopts=(
18-
--silent
19-
--show-error
20-
--fail
21-
--location
22-
--retry 3
23-
--max-time 4
24-
)
25-
# fetch canonical_data
26-
canonical_json=$(curl "${curlopts[@]}" "https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/${slug}/canonical-data.json")
27-
echo "$canonical_json" >>canonical_data.json
17+
canonical_json=$(bin/generator-utils/fetch_canonical_data "$slug")
18+
echo "$canonical_json" >canonical_data.json
2819

2920
if [ "${canonical_json}" == "404: Not Found" ]; then
3021
canonical_json=$(jq --null-input '{cases: []}')

0 commit comments

Comments
 (0)