add functions

This commit is contained in:
yequari 2023-09-24 11:48:28 -07:00
parent 7386b12f27
commit b306b0cc96
5 changed files with 53 additions and 10 deletions

9
.gitmodules vendored Normal file
View File

@ -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

View File

@ -27,16 +27,25 @@ get_changes() {
fi 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}" cp -r "${SRCDIR/*}" "${OUTDIR}"
} }
main() { update_publish() {
echo "$@"
OUTDIR="$1"
if [[ ! -d "$OUTDIR" ]]; then
echo "Invalid directory $OUTDIR"
fi
if [[ -n "$SRCDIR" ]]; then if [[ -n "$SRCDIR" ]]; then
cd "${SRCDIR}" cd "${SRCDIR}"
fi fi
@ -51,14 +60,26 @@ main() {
diff "${SRCDIR} ${OUTDIR}" diff "${SRCDIR} ${OUTDIR}"
local rc=$? local rc=$?
if [[ $rc -eq 1 ]]; then if [[ $rc -eq 1 ]]; then
publish copy_to_dest
fi 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= BRANCH=
FILE= FILE=
PUBONLY=false PUBONLY=false
OUTDIR=
while getopts ":hd:f:b:p" option; do while getopts ":hd:f:b:p" option; do
case $option in case $option in
@ -78,5 +99,15 @@ while getopts ":hd:f:b:p" option; do
exit;; exit;;
esac esac
done 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}"

1
test/bats Submodule

@ -0,0 +1 @@
Subproject commit fb7d15b519adeebafd642c085efc847ab8b2f25d

@ -0,0 +1 @@
Subproject commit 42e4d8622eda821d8c7c1a9fdcdbef54c642cf59

@ -0,0 +1 @@
Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009