diff --git a/src/usr/local/bin/autodoc b/src/usr/local/bin/autodoc index 6699d98..3be9df9 100755 --- a/src/usr/local/bin/autodoc +++ b/src/usr/local/bin/autodoc @@ -1,7 +1,5 @@ #!/bin/bash -echo -n "Loading '${0}': " - # # hard globals # @@ -21,13 +19,27 @@ for plugin in "${g_lib}/plugins/"*".sh"; do source "${plugin}" done -echo "program parsed." - # # MAIN # -echo "Building everything in '${g_watchroot}'." -do_build_all -echo "Watching '${g_watchroot}'." -do_build_watch +# 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 +fi + +echo "Done." diff --git a/src/usr/local/lib/autodoc/globals b/src/usr/local/lib/autodoc/globals index 5bea44e..595aba1 100644 --- a/src/usr/local/lib/autodoc/globals +++ b/src/usr/local/lib/autodoc/globals @@ -9,7 +9,59 @@ declare -A g_build_systems_glob # map of annotation patterns for build systems declare -A g_build_systems_annotations -# $WATCHROOT (default: ".") -g_watchroot="$(readlink -f "${1:-.}")" +# simple help page +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 ... " \ No newline at end of file +# 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:-.}")" \ No newline at end of file diff --git a/src/usr/local/lib/autodoc/logging b/src/usr/local/lib/autodoc/logging index 8d2a632..802d576 100644 --- a/src/usr/local/lib/autodoc/logging +++ b/src/usr/local/lib/autodoc/logging @@ -10,5 +10,3 @@ logline_flush() { echo "${g_logline}" g_logline="" } - -echo -n "logging ... " diff --git a/src/usr/local/lib/autodoc/main b/src/usr/local/lib/autodoc/main index d2ffd23..d9b874b 100644 --- a/src/usr/local/lib/autodoc/main +++ b/src/usr/local/lib/autodoc/main @@ -33,13 +33,13 @@ do_compile() { # $DIR $OBJECT $DONE && local done="1" done - # never leave $g_watchroot - if [ "${dir}" != "${g_watchroot}" ]; then + # never leave $g_root + if [ "${dir}" != "${g_root}" ]; then # search parent dir for more build instructions do_compile "$(dirname "${dir}")" "${object}" "${done}" elif [ "${done}" == "0" ]; then - # hit $g_watchroot + # hit $g_root logline_append "Not a source file." fi } @@ -113,7 +113,7 @@ do_build_all() { # for glob in ${g_build_systems_glob[${build_system}]}; do # match each glob recursively - find "${g_watchroot}" -iname "${glob}" | \ + find "${g_root}" -iname "${glob}" | \ while read file; do if [ -r "${file}" ]; then # force call into build system @@ -138,11 +138,9 @@ do_build_watch() { # inotifywait -mrq \ -e create -e delete -e moved_to -e close_write \ --format '%e %w%f' \ - "${g_watchroot}" | \ + "${g_root}" | \ \ while read NOTIFICATION; do do_handle_inotify ${NOTIFICATION} done } - -echo -n "main ... " diff --git a/src/usr/local/lib/autodoc/plugins/make.sh b/src/usr/local/lib/autodoc/plugins/make.sh index e4ecab1..d836faa 100644 --- a/src/usr/local/lib/autodoc/plugins/make.sh +++ b/src/usr/local/lib/autodoc/plugins/make.sh @@ -54,6 +54,4 @@ do_run_make() { # $DIR $MAKEFILE logline_append "$(echo "${makelog}" | head -n 10 | sed 's/$/;/g' | tr '\n' ' ' | sed 's/ *$//')" logline_append "Done." -} - -echo -n "GNU Make plugin ... " +} \ No newline at end of file