mirror of https://github.com/thesofproject/sof.git
gen-doc.sh: Use getopts for parsing arguments
Use getopts to parse the arguments instead of manual parsing to leave no room for errors, bugs, and inconsistent conventions introduced by custom implementation. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
This commit is contained in:
parent
1213bc2450
commit
79b39ccc9b
|
@ -28,31 +28,23 @@ DOCS_REPO="$(dirname "$SOF_REPO")/sof-docs"
|
||||||
PUBLISH_REPO="$(dirname "$SOF_REPO")/thesofproject.github.io"
|
PUBLISH_REPO="$(dirname "$SOF_REPO")/thesofproject.github.io"
|
||||||
|
|
||||||
# parse arguments
|
# parse arguments
|
||||||
DO_BUILD=no
|
DO_BUILD=false
|
||||||
DO_CLEAN=no
|
DO_CLEAN=false
|
||||||
DO_PUBLISH=no
|
DO_PUBLISH=false
|
||||||
DO_CLONE=no
|
DO_FETCH=false
|
||||||
|
|
||||||
for args in $@
|
while getopts "bcpr" OPTION; do
|
||||||
do
|
case "$OPTION" in
|
||||||
if [[ "$args" == "-b" ]]
|
b) DO_BUILD=true ;;
|
||||||
then
|
c) DO_CLEAN=true ;;
|
||||||
DO_BUILD=yes
|
p) DO_PUBLISH=true ;;
|
||||||
elif [[ "$args" == "-c" ]]
|
r) DO_FETCH=true ;;
|
||||||
then
|
*) print_usage; exit 1 ;;
|
||||||
DO_CLEAN=yes
|
esac
|
||||||
elif [[ "$args" == "-p" ]]
|
|
||||||
then
|
|
||||||
DO_PUBLISH=yes
|
|
||||||
elif [[ "$args" == "-r" ]]
|
|
||||||
then
|
|
||||||
DO_CLONE=yes
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
shift "$(($OPTIND - 1))"
|
||||||
|
|
||||||
if [ "x$DO_BUILD" == "xno" ] && \
|
if ! { "$DO_BUILD" || "$DO_CLEAN" || "$DO_PUBLISH"; }
|
||||||
[ "x$DO_CLEAN" == "xno" ] && \
|
|
||||||
[ "x$DO_PUBLISH" == "xno" ]
|
|
||||||
then
|
then
|
||||||
print_usage
|
print_usage
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -60,7 +52,7 @@ fi
|
||||||
|
|
||||||
if [ ! -d "$DOCS_REPO" ]
|
if [ ! -d "$DOCS_REPO" ]
|
||||||
then
|
then
|
||||||
if [ "x$DO_CLONE" == "xyes" ]
|
if "$DO_FETCH"
|
||||||
then
|
then
|
||||||
echo "No sof-docs repo at: $DOCS_REPO"
|
echo "No sof-docs repo at: $DOCS_REPO"
|
||||||
echo "Cloning sof-docs repo"
|
echo "Cloning sof-docs repo"
|
||||||
|
@ -83,7 +75,7 @@ fi
|
||||||
|
|
||||||
cd "$SOF_REPO/doc"
|
cd "$SOF_REPO/doc"
|
||||||
|
|
||||||
if [ "x$DO_CLEAN" == "xyes" ]
|
if "$DO_CLEAN"
|
||||||
then
|
then
|
||||||
echo "Cleaning $SOF_REPO"
|
echo "Cleaning $SOF_REPO"
|
||||||
cmake .
|
cmake .
|
||||||
|
@ -91,7 +83,7 @@ then
|
||||||
make doc-clean
|
make doc-clean
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$DO_BUILD" == "xyes" ]
|
if "$DO_BUILD"
|
||||||
then
|
then
|
||||||
echo "Building $SOF_REPO"
|
echo "Building $SOF_REPO"
|
||||||
cmake .
|
cmake .
|
||||||
|
@ -100,13 +92,13 @@ fi
|
||||||
|
|
||||||
cd "$DOCS_REPO"
|
cd "$DOCS_REPO"
|
||||||
|
|
||||||
if [ "x$DO_CLEAN" == "xyes" ]
|
if "$DO_CLEAN"
|
||||||
then
|
then
|
||||||
echo "Cleaning $DOCS_REPO"
|
echo "Cleaning $DOCS_REPO"
|
||||||
make clean
|
make clean
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$DO_BUILD" == "xyes" ]
|
if "$DO_BUILD"
|
||||||
then
|
then
|
||||||
echo "Building $DOCS_REPO"
|
echo "Building $DOCS_REPO"
|
||||||
make html
|
make html
|
||||||
|
@ -115,12 +107,12 @@ then
|
||||||
echo "It can be viewed at: $DOCS_REPO/_build/html/index.html"
|
echo "It can be viewed at: $DOCS_REPO/_build/html/index.html"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$DO_PUBLISH" == "xyes" ]
|
if "$DO_PUBLISH"
|
||||||
then
|
then
|
||||||
if [ ! -d "$PUBLISH_REPO" ]
|
if [ ! -d "$PUBLISH_REPO" ]
|
||||||
then
|
then
|
||||||
|
|
||||||
if [ "x$DO_CLONE" == "xyes" ]
|
if "$DO_FETCH"
|
||||||
then
|
then
|
||||||
echo "No publishing repo at: $PUBLISH_REPO"
|
echo "No publishing repo at: $PUBLISH_REPO"
|
||||||
echo "Cloning thesofproject.github.io.git repo"
|
echo "Cloning thesofproject.github.io.git repo"
|
||||||
|
|
Loading…
Reference in New Issue