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
}
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
@ -79,4 +100,14 @@ while getopts ":hd:f:b:p" option; do
esac
done
main "${@:$OPTIND}"
if [[ -z "$FILE" ]]; then
OUTDIR="${@:$OPTIND:1}"
echo "$OUTDIR"
if [[ ! -d "$OUTDIR" ]]; then
echo "Directory \"${OUTDIR}\" does not exist"
exit 1
fi
fi
main

1
test/bats Submodule

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

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

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