diff --git a/bin/nux-runner b/bin/nux-runner index 65c635a..8af49a9 100755 --- a/bin/nux-runner +++ b/bin/nux-runner @@ -106,7 +106,7 @@ task.() { ## interactive:: -## Executes interactive application shell. +## Executes interactive application shell. task.interactive() { nuxr.task.interactive "$@" } @@ -115,19 +115,32 @@ task.interactive() { if [ "$NUX_RUNNER" = "$(realpath "$0")" ] then - readonly NUX_SCRIPT=$1; + NUX_SCRIPT=$1; shift; else - readonly NUX_SCRIPT=$0; - readonly NUX_NO_INCLUDE="no include"; + NUX_SCRIPT=$0; + NUX_NO_INCLUDE="no include"; fi if [ -n "$NUX_SCRIPT" ]; then # Determines script - readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT) - readonly NUX_APPNAME=$(basename $NUX_SCRIPT) - nuxr.run "$@" + NUX_SCRIPT_DIR=$(dirname "$NUX_SCRIPT") + NUXR_APP_BIN=$(realpath "$NUX_SCRIPT") + NUXR_APP_BIN_DIR=$(dirname "$NUXR_APP_BIN") + NUXR_APP_DIR=$(dirname "$NUXR_APP_BIN_DIR") + NUXR_APP_NAME=$(basename "$NUX_SCRIPT") + NUX_SCRIPTNAME=$(basename "$NUX_SCRIPT") + + nux.log trace "NUX_SCRIPT env: " $(set | grep NUX_SCRIPT) + if [ -z "$NUX_NO_INCLUDE" ] + then + nux.log debug "Including script: $NUX_SCRIPT" + nux.log trace "NUX_SCRIPT env: " $(set | grep NUX_SCRIPT) + source $NUX_SCRIPT; # Includes script + NUX_NO_INCLUDE="no-include" + fi + nuxr.main "$@" else echo Usage: nux-runner [script] [task] [options] diff --git a/inc/nux-runner.inc.sh b/inc/nux-runner.inc.sh index 169a3c3..ce1f3c6 100644 --- a/inc/nux-runner.inc.sh +++ b/inc/nux-runner.inc.sh @@ -1,22 +1,34 @@ nuxr.run() { TASK=$1; shift; # Determines task - if [ -z "$NUX_NO_INCLUDE" ] - then - nux.log debug "Including script: $NUX_SCRIPT" - source $NUX_SCRIPT; # Includes script - fi if nux.check.function task.$TASK ; then nux.log debug "Running task: $TASK"; task.$TASK "$@" # Runs task else echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available." echo "Try '$NUX_SCRIPTNAME help' for more information." - exit -1 + return -1 fi } + +nuxr.run.subtask() { + SUBTASK=$1; shift; + if nux.check.function task.$TASK.$SUBTASK ; then + nux.log debug "Running subtask: $TASK"; + task.$TASK.$SUBTASK "$@" # Runs task + else + echo "$NUX_SCRIPTNAME: '$TASK' '$SUBTASK' not available." + echo "Try '$NUX_SCRIPTNAME help' for more information." + fi +} + +nuxr.main() { + nuxr.run "$@" +} + function nuxr.task.help { - if [ -z "$@" ] ; then + allArgs="$@" + if [ -z "$allArgs" ] ; then echo Usage: $NC_Bold$NUX_SCRIPTNAME ${NC_No}${NC_White}\${NC_No} [\] nux.help.comment "$NUX_SCRIPT" nux.help.comment "$NUX_RUNNER" @@ -27,9 +39,10 @@ function nuxr.task.help { } function nuxr.task.help.topic { - topic="$1" - nux.log trace "Displaying topic for: $topic" - if nux.check.function "task.help.$topic" ; then + topic="$@" + topic_dot=$(tr " " "." <<< $topic) + nux.log trace "Displaying topic for: '$topic' '$topic_dot'" + if nux.check.function "task.help.$topic_dot" ; then shift; task.help.$topic "$@"; else @@ -42,10 +55,10 @@ function nuxr.task.help.topic { function nuxr.help.task.comment { local script="$1" local task="$2" - - nux.log trace "Trying to figure task documentation location for $@" + local task_dot=$(tr " " "." <<< "$task") + nux.log trace "Trying to figure task documentation location for $task $task_dot" doc_start=$(grep -hn -E "## +($task)::" "$script" | cut -d: -f1) - code_start=$(grep -hn -E "((function +task.$task)|(task.$task *\(\))) +{" "$script" | cut -d: -f1) + code_start=$(grep -hn -E "((function +task.$task_dot)|(task.$task_dot *\(\))) +{" "$script" | cut -d: -f1) nux.log trace "doc_start" $doc_start $code_start if [ -n "$doc_start" -a -n "$code_start" ] ; then sed -n "$doc_start,$code_start"p "$script" \