From 16dff916cd9b784fba9ec56f6f10bc8d5184ddbd Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 26 Jun 2021 19:35:07 -0300 Subject: aux/ci/report.sh: Use getopts for arguments --- aux/ci/ci-build.sh | 2 +- aux/ci/report.sh | 26 ++++++++++++++++++++++++-- aux/workflow/public.sh | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'aux') diff --git a/aux/ci/ci-build.sh b/aux/ci/ci-build.sh index 7fa3382..be97866 100755 --- a/aux/ci/ci-build.sh +++ b/aux/ci/ci-build.sh @@ -26,7 +26,7 @@ EOF git notes append -m "$NOTE" cd - - sh aux/ci/report.sh "$PROJECT" public + sh aux/ci/report.sh -n "$PROJECT" -o public rsync -av public/ "/srv/http/$PROJECT/" --delete printf "\n>>>\n>>> CI logs added as Git note.\n>>>\n>>> Run status was %s" "$STATUS" diff --git a/aux/ci/report.sh b/aux/ci/report.sh index c873f54..69dbea3 100755 --- a/aux/ci/report.sh +++ b/aux/ci/report.sh @@ -1,9 +1,31 @@ #!/bin/sh set -eu -PROJECT="$1" -OUTDIR="$2" TLD="$(cat aux/tld.txt)" +while getopts 'n:o:' flag; do + case "$flag" in + n) + PROJECT="$OPTARG" + ;; + o) + OUTDIR="$OPTARG" + ;; + *) + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +assert_arg() { + if [ -z "$1" ]; then + echo "Missing $2" >&2 + exit 2 + fi +} + +assert_arg "${PROJECT:-}" '-n PROJECT' +assert_arg "${OUTDIR:-}" '-o OUTDIR' PASS='✅' FAIL='❌' diff --git a/aux/workflow/public.sh b/aux/workflow/public.sh index b791042..b78b924 100755 --- a/aux/workflow/public.sh +++ b/aux/workflow/public.sh @@ -46,6 +46,6 @@ if [ -f CHANGELOG.md ]; then sh aux/workflow/commonmark.sh -N "$PROJECT" -o "$OUTDIR" -r CHANGELOG.md fi -sh aux/ci/report.sh "$PROJECT" "$OUTDIR" +sh aux/ci/report.sh -n "$PROJECT" -o "$OUTDIR" cp aux/workflow/favicon.svg aux/workflow/favicon.png "$OUTDIR" -- cgit v1.2.3