From b306b0cc96ba2feffb4763558755086a8e564165 Mon Sep 17 00:00:00 2001 From: yequari Date: Sun, 24 Sep 2023 11:48:28 -0700 Subject: [PATCH] add functions --- .gitmodules | 9 +++++++ site-update.sh | 51 ++++++++++++++++++++++++++++------- test/bats | 1 + test/test_helper/bats-assert | 1 + test/test_helper/bats-support | 1 + 5 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 .gitmodules create mode 160000 test/bats create mode 160000 test/test_helper/bats-assert create mode 160000 test/test_helper/bats-support diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7efcb4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "test/bats"] + path = test/bats + url = https://github.com/bats-core/bats-core.git +[submodule "test/test_helper/bats-support"] + path = test/test_helper/bats-support + url = https://github.com/bats-core/bats-support.git +[submodule "test/test_helper/bats-assert"] + path = test/test_helper/bats-assert + url = https://github.com/bats-core/bats-assert.git diff --git a/site-update.sh b/site-update.sh index 3b8836b..c1315bf 100755 --- a/site-update.sh +++ b/site-update.sh @@ -27,16 +27,25 @@ get_changes() { fi } -publish () { +change_directory() { + if [[ -n "$SRCDIR" ]]; then + cd "${SRCDIR}" + fi +} + +checkout_branch() { + if [[ -n "$BRANCH" ]]; then + git checkout "${BRANCH}" + else + BRANCH=$(git branch --show-current) + fi +} + +copy_to_dest () { cp -r "${SRCDIR/*}" "${OUTDIR}" } -main() { - echo "$@" - OUTDIR="$1" - if [[ ! -d "$OUTDIR" ]]; then - echo "Invalid directory $OUTDIR" - fi +update_publish() { if [[ -n "$SRCDIR" ]]; then cd "${SRCDIR}" fi @@ -51,14 +60,26 @@ main() { diff "${SRCDIR} ${OUTDIR}" local rc=$? if [[ $rc -eq 1 ]]; then - publish + copy_to_dest fi } -SRCDIR= +main() { + if [[ -f "$FILE" ]]; then + while read -r src out rem; do + # use rem as dummy variable to guarantee out countains one word + echo "${src} | ${out} | ${rem}" + done < "${FILE}" + else + update_publish + fi +} + +SRCDIR=$(pwd) BRANCH= FILE= PUBONLY=false +OUTDIR= while getopts ":hd:f:b:p" option; do case $option in @@ -78,5 +99,15 @@ while getopts ":hd:f:b:p" option; do exit;; esac done + +if [[ -z "$FILE" ]]; then + OUTDIR="${@:$OPTIND:1}" + echo "$OUTDIR" + if [[ ! -d "$OUTDIR" ]]; then + echo "Directory \"${OUTDIR}\" does not exist" + exit 1 + fi +fi + +main -main "${@:$OPTIND}" diff --git a/test/bats b/test/bats new file mode 160000 index 0000000..fb7d15b --- /dev/null +++ b/test/bats @@ -0,0 +1 @@ +Subproject commit fb7d15b519adeebafd642c085efc847ab8b2f25d diff --git a/test/test_helper/bats-assert b/test/test_helper/bats-assert new file mode 160000 index 0000000..42e4d86 --- /dev/null +++ b/test/test_helper/bats-assert @@ -0,0 +1 @@ +Subproject commit 42e4d8622eda821d8c7c1a9fdcdbef54c642cf59 diff --git a/test/test_helper/bats-support b/test/test_helper/bats-support new file mode 160000 index 0000000..3c8fadc --- /dev/null +++ b/test/test_helper/bats-support @@ -0,0 +1 @@ +Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009