Skip to content

Commit

Permalink
Make create_challenge not verbose by default
Browse files Browse the repository at this point in the history
Allow for verbose output with -v
  • Loading branch information
miallo committed Jan 8, 2024
1 parent c332e1d commit d12d4c8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This is the (WIP) script for creating an interactive `git` repo that is a completely self-contained `git` tutorial. To create a local "playable" copy run `./create_challenge.sh`. The challenge itself is only in the then created folder "challenge" and NOT in this repository. Do NOT look around in this repository unless you want to develop this challenge, because otherwise you will be spoiled with the solutions ;)

## debugging

By default `./create_challenge.sh` does not show the git output to avoid leaking information. If you get an error you can run it again with `-v`/`--verbose`.

## testing

Expand Down
25 changes: 24 additions & 1 deletion create_challenge.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#!/usr/bin/env bash

while [ $# -gt 0 ]; do
case "$1" in
-v|--verbose)
verbose=true
shift
;;
*)
echo "ERROR! Unknown option '$1'. Useage: $0 [-v|--verbose]" >&2
exit 1
;;
esac
done

if [ "$verbose" != true ]; then
exec 3>&1 4>&2 >/dev/null 2>&1 # store stdin / stdout filedescriptors so that we can still print in case of an error
fi
on_error() {
exec 1>&3 2>&4 # restore file descriptors
printf "❌ \e[3;1;31mERROR! Run again with \`-v\` for more verbose output\e[0m\n" >&2
exit 1
}
trap on_error ERR

set -e
shopt -s extglob
. ./lib.sh
Expand All @@ -9,7 +32,7 @@ if [ -e challenge ]; then
rm -rf challenge2
mv challenge challenge2
fi
. ./src/redeem.nuggit >/dev/null 2>&1
. ./src/redeem.nuggit

LOCAL_CODE_EXECUTION_HASH="$(success "LocalCodeExecution" | git hash-object --stdin)"
NUMBER_OF_NUGGITS="$(wc -l <"$DOCDIR/nuggits")"
Expand Down
2 changes: 1 addition & 1 deletion lib-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it(){
trap 'failure $(printf "%q" "$testname")' ERR EXIT
$code
trap - EXIT # Remove the trap handler, so that it does not fire at the end of the script
" >/dev/null
"
success "$testname"
}

Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
. ./lib.sh
. ./lib-test.sh
echo "Building..."
./create_challenge.sh >/dev/null 2>&1
./create_challenge.sh
cd challenge
reproducibility_setup

Expand All @@ -27,7 +27,7 @@ check_redeem_without_local_code_execution

echo "Building once more..."
cd ..
./create_challenge.sh >/dev/null 2>&1
./create_challenge.sh
echo "Running tests..."
cd challenge
reproducibility_setup
Expand Down

0 comments on commit d12d4c8

Please sign in to comment.