Add command-line options to add-exercise script. (#149)
Additional shellcheck suggestions.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
scriptname=$0
|
||||
|
||||
if (( $# < 1 )); then
|
||||
help_and_exit() {
|
||||
echo >&2 "Populates a new directory for a practice exercise."
|
||||
echo >&2 "Usage: $0 <exercise-slug> [author]"
|
||||
echo >&2 "Usage: ${scriptname} [-h] [-a author] <exercise-slug>"
|
||||
echo >&2 "Where: author is the github username of the exercise creator."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
die() { echo >&2 "$*"; exit 1; }
|
||||
|
||||
@@ -14,11 +16,24 @@ 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."
|
||||
}
|
||||
|
||||
(( $# >= 1 )) || help_and_exit
|
||||
|
||||
required_tool jq
|
||||
required_tool curl
|
||||
|
||||
[[ -f ./bin/fetch-configlet ]] || die "run this script from the repo's root directory."
|
||||
|
||||
author=''
|
||||
while getopts :ha: opt; do
|
||||
case $opt in
|
||||
h) help_and_exit ;;
|
||||
a) author=$OPTARG ;;
|
||||
?) echo >&2 "Unknown option: -$OPTARG"; help_and_exit ;;
|
||||
esac
|
||||
done
|
||||
shift "$((OPTIND - 1))"
|
||||
|
||||
slug="${1}"
|
||||
|
||||
# Create entry for exercise in config.json and exercise files
|
||||
@@ -39,11 +54,9 @@ end-of-tests
|
||||
;with
|
||||
END_TEST
|
||||
|
||||
if (( $# < 2 )); then
|
||||
if [[ -z $author ]]; then
|
||||
echo
|
||||
read -rp 'Your github username: ' author
|
||||
else
|
||||
author="${2}"
|
||||
fi
|
||||
|
||||
conf="exercises/practice/${slug}/.meta/config.json"
|
||||
@@ -64,5 +77,5 @@ Your next steps are:
|
||||
- Verify the example solution by running 'bin/test-no-docker ${slug}'
|
||||
- Create the stub solution in 'exercises/practice/${slug}/${slug}.8th'
|
||||
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file
|
||||
- Validate CI using 'bin/configlet lint'
|
||||
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt'
|
||||
NEXT_STEPS
|
||||
|
||||
12
bin/test
12
bin/test
@@ -24,7 +24,7 @@ function run_test_runner() {
|
||||
}
|
||||
|
||||
function verify_exercise() {
|
||||
local dir=$(realpath $1)
|
||||
local dir=$(realpath "$1")
|
||||
local slug=$(basename "${dir}")
|
||||
local implementation_file_key=$2
|
||||
local implementation_file=$(jq -r --arg d "${dir}" --arg k "${implementation_file_key}" '$d + "/" + .files[$k][0]' "${dir}/.meta/config.json")
|
||||
@@ -49,18 +49,18 @@ function verify_exercise() {
|
||||
|
||||
# Verify the Concept Exercises
|
||||
for concept_exercise_dir in ./exercises/concept/*/; do
|
||||
if [ -d $concept_exercise_dir ]; then
|
||||
if [[ -d $concept_exercise_dir ]]; then
|
||||
echo "Checking $(basename "${concept_exercise_dir}") exercise..."
|
||||
verify_exercise $concept_exercise_dir "exemplar"
|
||||
verify_exercise "$concept_exercise_dir" "exemplar"
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify the Practice Exercises
|
||||
for practice_exercise_dir in ./exercises/practice/*/; do
|
||||
if [ -d $practice_exercise_dir ]; then
|
||||
if [[ -d $practice_exercise_dir ]]; then
|
||||
echo "Checking $(basename "${practice_exercise_dir}") exercise..."
|
||||
verify_exercise $practice_exercise_dir "example"
|
||||
verify_exercise "$practice_exercise_dir" "example"
|
||||
fi
|
||||
done
|
||||
|
||||
exit ${exit_code}
|
||||
exit "${exit_code}"
|
||||
|
||||
@@ -15,7 +15,7 @@ make_test_dir() {
|
||||
local slug=${exercise_dir##*/}
|
||||
local key=$2
|
||||
(
|
||||
cd "$exercise_dir"
|
||||
cd "$exercise_dir" || die "cannot cd to: $exercise_dir"
|
||||
[[ -f test-words.8th ]] && cp test-words.8th "$test_dir"
|
||||
[[ -d libs ]] && cp -r libs "$test_dir"
|
||||
while IFS= read -r test; do
|
||||
|
||||
Reference in New Issue
Block a user