mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nux-runner: Added subtask support
Added support for subtasks in shell form task.parent.subtask
- task could by invoked from shell:
[app] [task] [subtask]
[app] [task.subtask]
- added support for subtasks to help system
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
bc350810b7
commit
654461dc02
2 changed files with 46 additions and 20 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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}\<command\>${NC_No} [\<options\>]
|
||||
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" \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue