Skip to content

Commit c56fba4

Browse files
committed
Add configlet fetching if it doesn't exist
1 parent 02e0cb0 commit c56fba4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

bin/add_practice_exercise

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env bash
22

3-
43
# see comment in generator-utils/utils.sh
5-
# shellcheck source=bin/generator-utils/utils.sh
6-
# shellcheck source=bin/generator-utils/templates.sh
7-
# shellcheck source=bin/generator-utils/prompts.sh
8-
# shellcheck source=./generator-utils/utils.sh
9-
# shellcheck source=./generator-utils/prompts.sh
10-
# shellcheck source=./generator-utils/templates.sh
4+
# shellcheck source=bin/generator-utils/utils.sh
5+
# shellcheck source=bin/generator-utils/templates.sh
6+
# shellcheck source=bin/generator-utils/prompts.sh
7+
# shellcheck source=./generator-utils/utils.sh
8+
# shellcheck source=./generator-utils/prompts.sh
9+
# shellcheck source=./generator-utils/templates.sh
1110

1211
source ./bin/generator-utils/utils.sh
1312
source ./bin/generator-utils/prompts.sh
@@ -38,12 +37,19 @@ command -v curl >/dev/null 2>&1 || {
3837
exit 1
3938
}
4039

40+
if [ -e bin/configlet ]; then
41+
message "success" "Configlet found!"
42+
else
43+
message "info" "Fetching configlet"
44+
bin/fetch-configlet
45+
message "success" "Fetched configlet successfully!"
46+
fi
47+
4148
# Check if exercise exists in configlet info or in config.json
4249
check_exercise_existence "$1"
4350

4451
# ==================================================
4552

46-
4753
slug="$1"
4854
# Fetch canonical data
4955
canonical_json=$(bin/fetch_canonical_data "$slug")
@@ -59,7 +65,6 @@ else
5965
message "success" "Fetched canonical data successfully!"
6066
fi
6167

62-
6368
underscored_slug=$(dash_to_underscore "$slug")
6469
exercise_dir="exercises/practice/${slug}"
6570
exercise_name=$(format_exercise_name "$slug")
@@ -87,7 +92,6 @@ uuid=$(bin/configlet uuid)
8792

8893
# Add exercise-data to global config.json
8994
jq --arg slug "$slug" --arg uuid "$uuid" --arg name "$exercise_name" --arg difficulty "$exercise_difficulty" \
90-
9195
'.exercises.practice += [{slug: $slug, name: $name, uuid: $uuid, practices: [], prerequisites: [], difficulty: $difficulty}]' \
9296
config.json >config.json.tmp
9397
# jq always rounds whole numbers, but average_run_time needs to be a float
@@ -110,10 +114,8 @@ message "success" "You've been added as the author of this exercise."
110114

111115
sed -i "s/name = \".*\"/name = \"$underscored_slug\"/" "$exercise_dir"/Cargo.toml
112116

113-
114117
message "done" "All stub files were created."
115118

116119
message "info" "After implementing the solution, tests and configuration, please run:"
117120

118121
echo "./bin/configlet fmt --update --yes --exercise ${slug}"
119-

0 commit comments

Comments
 (0)