mirror of
https://github.com/ldericher/autodoc.git
synced 2025-12-06 15:43:01 +00:00
better CLI options
This commit is contained in:
parent
0022106d97
commit
661e94aa13
5 changed files with 81 additions and 23 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo -n "Loading '${0}': "
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# hard globals
|
# hard globals
|
||||||
#
|
#
|
||||||
|
|
@ -21,13 +19,27 @@ for plugin in "${g_lib}/plugins/"*".sh"; do
|
||||||
source "${plugin}"
|
source "${plugin}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "program parsed."
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# MAIN
|
# MAIN
|
||||||
#
|
#
|
||||||
echo "Building everything in '${g_watchroot}'."
|
|
||||||
do_build_all
|
|
||||||
|
|
||||||
echo "Watching '${g_watchroot}'."
|
# show debug info
|
||||||
|
if [ ${g_verbose} -eq 1 ]; then
|
||||||
|
logline_append "Variables:"
|
||||||
|
logline_append "build:${g_build}"
|
||||||
|
logline_append "watch:${g_watch}"
|
||||||
|
logline_append "root:${g_root}"
|
||||||
|
logline_flush
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${g_build} -eq 1 ]; then
|
||||||
|
echo "Building everything in '${g_root}'."
|
||||||
|
do_build_all
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${g_watch} -eq 1 ]; then
|
||||||
|
echo "Watching '${g_root}'."
|
||||||
do_build_watch
|
do_build_watch
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,59 @@ declare -A g_build_systems_glob
|
||||||
# map of annotation patterns for build systems
|
# map of annotation patterns for build systems
|
||||||
declare -A g_build_systems_annotations
|
declare -A g_build_systems_annotations
|
||||||
|
|
||||||
# $WATCHROOT (default: ".")
|
# simple help page
|
||||||
g_watchroot="$(readlink -f "${1:-.}")"
|
do_show_help() {
|
||||||
|
echo "Usage: ${0} [-h?bwv] [-r ROOT] [ROOT]"
|
||||||
|
echo
|
||||||
|
echo "Options:"
|
||||||
|
echo " -h, -? Show this help and exit"
|
||||||
|
echo " -b Build ROOT directory on startup"
|
||||||
|
echo " -w Keep watching ROOT directory for changes"
|
||||||
|
echo " -v Verbose output"
|
||||||
|
echo " -r ROOT Set ROOT directory"
|
||||||
|
echo
|
||||||
|
echo "ROOT directory can be set via '-r' argument or positionally."
|
||||||
|
echo "If ROOT directory is undefined, it defaults to the current working directory."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
echo -n "globals ... "
|
# reset in case getopts has been used previously in the shell
|
||||||
|
OPTIND=1
|
||||||
|
|
||||||
|
# initialize variables
|
||||||
|
g_build=0
|
||||||
|
g_watch=0
|
||||||
|
g_root=""
|
||||||
|
|
||||||
|
while getopts "h?bwvr:" opt; do
|
||||||
|
case "$opt" in
|
||||||
|
h|\?)
|
||||||
|
do_show_help
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
g_build=1
|
||||||
|
;;
|
||||||
|
w)
|
||||||
|
g_watch=1
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
g_verbose=1
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
g_root="${OPTARG}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# default to help
|
||||||
|
[ ${g_build} -eq 0 ] && [ ${g_watch} -eq 0 ] && [ ${g_verbose} -eq 0 ] && do_show_help
|
||||||
|
|
||||||
|
# shift off getopts parsed options
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
[ "${1:-}" = "--" ] && shift
|
||||||
|
|
||||||
|
# if g_root undefined by getopt,
|
||||||
|
[ -z "${g_root:-}" ] && g_root="$1"
|
||||||
|
|
||||||
|
# get actual $ROOT directory (default: ".")
|
||||||
|
g_root="$(readlink -f "${g_root:-.}")"
|
||||||
|
|
@ -10,5 +10,3 @@ logline_flush() {
|
||||||
echo "${g_logline}"
|
echo "${g_logline}"
|
||||||
g_logline=""
|
g_logline=""
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -n "logging ... "
|
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ do_compile() { # $DIR $OBJECT $DONE
|
||||||
&& local done="1"
|
&& local done="1"
|
||||||
done
|
done
|
||||||
|
|
||||||
# never leave $g_watchroot
|
# never leave $g_root
|
||||||
if [ "${dir}" != "${g_watchroot}" ]; then
|
if [ "${dir}" != "${g_root}" ]; then
|
||||||
# search parent dir for more build instructions
|
# search parent dir for more build instructions
|
||||||
do_compile "$(dirname "${dir}")" "${object}" "${done}"
|
do_compile "$(dirname "${dir}")" "${object}" "${done}"
|
||||||
|
|
||||||
elif [ "${done}" == "0" ]; then
|
elif [ "${done}" == "0" ]; then
|
||||||
# hit $g_watchroot
|
# hit $g_root
|
||||||
logline_append "Not a source file."
|
logline_append "Not a source file."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +113,7 @@ do_build_all() { #
|
||||||
for glob in ${g_build_systems_glob[${build_system}]}; do
|
for glob in ${g_build_systems_glob[${build_system}]}; do
|
||||||
|
|
||||||
# match each glob recursively
|
# match each glob recursively
|
||||||
find "${g_watchroot}" -iname "${glob}" | \
|
find "${g_root}" -iname "${glob}" | \
|
||||||
while read file; do
|
while read file; do
|
||||||
if [ -r "${file}" ]; then
|
if [ -r "${file}" ]; then
|
||||||
# force call into build system
|
# force call into build system
|
||||||
|
|
@ -138,11 +138,9 @@ do_build_watch() { #
|
||||||
inotifywait -mrq \
|
inotifywait -mrq \
|
||||||
-e create -e delete -e moved_to -e close_write \
|
-e create -e delete -e moved_to -e close_write \
|
||||||
--format '%e %w%f' \
|
--format '%e %w%f' \
|
||||||
"${g_watchroot}" | \
|
"${g_root}" | \
|
||||||
\
|
\
|
||||||
while read NOTIFICATION; do
|
while read NOTIFICATION; do
|
||||||
do_handle_inotify ${NOTIFICATION}
|
do_handle_inotify ${NOTIFICATION}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -n "main ... "
|
|
||||||
|
|
|
||||||
|
|
@ -55,5 +55,3 @@ do_run_make() { # $DIR $MAKEFILE
|
||||||
|
|
||||||
logline_append "Done."
|
logline_append "Done."
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -n "GNU Make plugin ... "
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue