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
|
|
@ -115,19 +115,32 @@ task.interactive() {
|
||||||
|
|
||||||
if [ "$NUX_RUNNER" = "$(realpath "$0")" ]
|
if [ "$NUX_RUNNER" = "$(realpath "$0")" ]
|
||||||
then
|
then
|
||||||
readonly NUX_SCRIPT=$1;
|
NUX_SCRIPT=$1;
|
||||||
shift;
|
shift;
|
||||||
else
|
else
|
||||||
readonly NUX_SCRIPT=$0;
|
NUX_SCRIPT=$0;
|
||||||
readonly NUX_NO_INCLUDE="no include";
|
NUX_NO_INCLUDE="no include";
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$NUX_SCRIPT" ]; then
|
if [ -n "$NUX_SCRIPT" ]; then
|
||||||
# Determines script
|
# Determines script
|
||||||
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
|
NUX_SCRIPT_DIR=$(dirname "$NUX_SCRIPT")
|
||||||
readonly NUX_APPNAME=$(basename $NUX_SCRIPT)
|
NUXR_APP_BIN=$(realpath "$NUX_SCRIPT")
|
||||||
nuxr.run "$@"
|
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
|
else
|
||||||
|
|
||||||
echo Usage: nux-runner [script] [task] [options]
|
echo Usage: nux-runner [script] [task] [options]
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,34 @@
|
||||||
nuxr.run() {
|
nuxr.run() {
|
||||||
TASK=$1; shift; # Determines task
|
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
|
if nux.check.function task.$TASK ; then
|
||||||
nux.log debug "Running task: $TASK";
|
nux.log debug "Running task: $TASK";
|
||||||
task.$TASK "$@" # Runs task
|
task.$TASK "$@" # Runs task
|
||||||
else
|
else
|
||||||
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
|
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
|
||||||
echo "Try '$NUX_SCRIPTNAME help' for more information."
|
echo "Try '$NUX_SCRIPTNAME help' for more information."
|
||||||
exit -1
|
return -1
|
||||||
fi
|
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 {
|
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\>]
|
echo Usage: $NC_Bold$NUX_SCRIPTNAME ${NC_No}${NC_White}\<command\>${NC_No} [\<options\>]
|
||||||
nux.help.comment "$NUX_SCRIPT"
|
nux.help.comment "$NUX_SCRIPT"
|
||||||
nux.help.comment "$NUX_RUNNER"
|
nux.help.comment "$NUX_RUNNER"
|
||||||
|
|
@ -27,9 +39,10 @@ function nuxr.task.help {
|
||||||
}
|
}
|
||||||
|
|
||||||
function nuxr.task.help.topic {
|
function nuxr.task.help.topic {
|
||||||
topic="$1"
|
topic="$@"
|
||||||
nux.log trace "Displaying topic for: $topic"
|
topic_dot=$(tr " " "." <<< $topic)
|
||||||
if nux.check.function "task.help.$topic" ; then
|
nux.log trace "Displaying topic for: '$topic' '$topic_dot'"
|
||||||
|
if nux.check.function "task.help.$topic_dot" ; then
|
||||||
shift;
|
shift;
|
||||||
task.help.$topic "$@";
|
task.help.$topic "$@";
|
||||||
else
|
else
|
||||||
|
|
@ -42,10 +55,10 @@ function nuxr.task.help.topic {
|
||||||
function nuxr.help.task.comment {
|
function nuxr.help.task.comment {
|
||||||
local script="$1"
|
local script="$1"
|
||||||
local task="$2"
|
local task="$2"
|
||||||
|
local task_dot=$(tr " " "." <<< "$task")
|
||||||
nux.log trace "Trying to figure task documentation location for $@"
|
nux.log trace "Trying to figure task documentation location for $task $task_dot"
|
||||||
doc_start=$(grep -hn -E "## +($task)::" "$script" | cut -d: -f1)
|
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
|
nux.log trace "doc_start" $doc_start $code_start
|
||||||
if [ -n "$doc_start" -a -n "$code_start" ] ; then
|
if [ -n "$doc_start" -a -n "$code_start" ] ; then
|
||||||
sed -n "$doc_start,$code_start"p "$script" \
|
sed -n "$doc_start,$code_start"p "$script" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue