mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nux-runner: Added support for additional REPL commands.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
1d3fd0b3c3
commit
47dcb3daca
1 changed files with 62 additions and 32 deletions
|
|
@ -16,19 +16,25 @@ nuxr.run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function nuxr.task.help {
|
function nuxr.task.help {
|
||||||
command="$1"
|
if [ -z "$@" ] ; then
|
||||||
nux.log trace "Displaying help command for: $command"
|
|
||||||
if [ -z $command ] ; 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"
|
||||||
nux.exec.optional task.help.additional
|
nux.exec.optional task.help.additional
|
||||||
elif nux.check.function "task.help.$command" ; then
|
|
||||||
shift;
|
|
||||||
task.help.$command "$@";
|
|
||||||
else
|
else
|
||||||
nuxr.help.task.comment "$NUX_SCRIPT" "$command" \
|
nuxr.task.help.topic "$@"
|
||||||
|| nuxr.help.task.comment "$NUX_RUNNER" "$command" \
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function nuxr.task.help.topic {
|
||||||
|
topic="$1"
|
||||||
|
nux.log trace "Displaying topic for: $topic"
|
||||||
|
if nux.check.function "task.help.$topic" ; then
|
||||||
|
shift;
|
||||||
|
task.help.$topic "$@";
|
||||||
|
else
|
||||||
|
nuxr.help.task.comment "$NUX_SCRIPT" "$topic" \
|
||||||
|
|| nuxr.help.task.comment "$NUX_RUNNER" "$topic" \
|
||||||
|| echo "Help topic $1 not found. Run '$NUX_APPNAME help' to see topics."
|
|| echo "Help topic $1 not found. Run '$NUX_APPNAME help' to see topics."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -58,20 +64,46 @@ function nuxr.help.task.comment {
|
||||||
##
|
##
|
||||||
nuxr.task.interactive() {
|
nuxr.task.interactive() {
|
||||||
nux.use nux.repl
|
nux.use nux.repl
|
||||||
.process() {
|
nux.repl.start nuxr.repl.process nuxr.repl.prompt nuxr.repl.completer
|
||||||
backendFunc=task.$command;
|
}
|
||||||
if nux.check.function $backendFunc; then
|
|
||||||
|
|
||||||
|
|
||||||
|
nuxr.repl.process() {
|
||||||
|
backendFunc=task.$command;
|
||||||
|
if nux.check.function repl.command.$command; then
|
||||||
|
eval repl.command.$command "$arguments"
|
||||||
|
elif nux.check.function task.$command; then
|
||||||
eval nuxr.run "$command" "$arguments"
|
eval nuxr.run "$command" "$arguments"
|
||||||
else
|
else
|
||||||
echo "$command" is not defined.
|
echo "$command" is not defined.
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
.prompt() {
|
##
|
||||||
echo "${nc_green}$NUX_APPNAME${nc_end}> "
|
## repl.command.::
|
||||||
|
## fallback command which does nothing if user just presses enter.
|
||||||
|
##
|
||||||
|
repl.command.() {
|
||||||
|
:
|
||||||
}
|
}
|
||||||
nux.repl.start .process .prompt nuxr.repl.completer
|
|
||||||
|
repl.command.help() {
|
||||||
|
if [ -z "$@" ] ;then
|
||||||
|
echo "Usage: help [<command> | <topic>]"
|
||||||
|
echo Displays help for specified topic or command.
|
||||||
|
echo
|
||||||
|
echo "${nc_white}Available topics:$nc_end"
|
||||||
|
nuxr.tasks.runtime.search help.$current_word | cut -d"." -f2 | column
|
||||||
|
echo
|
||||||
|
echo "${nc_white}Available commands:$nc_end"
|
||||||
|
nuxr.tasks.runtime.search $current_word | grep -v "help\\." | column
|
||||||
|
else
|
||||||
|
nuxr.task.help.topic "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
nuxr.repl.prompt() {
|
||||||
|
echo "${nc_green}$NUX_APPNAME${nc_end}> "
|
||||||
}
|
}
|
||||||
|
|
||||||
nuxr.tasks.runtime.search() {
|
nuxr.tasks.runtime.search() {
|
||||||
|
|
@ -105,20 +137,18 @@ nuxr.repl.completer() {
|
||||||
|
|
||||||
local words=($line)
|
local words=($line)
|
||||||
local current_pos=${#words[@]};
|
local current_pos=${#words[@]};
|
||||||
if [ "$current_pos" -eq 0 ]; then
|
local current_word="";
|
||||||
nuxr.tasks.runtime.search | sort | uniq
|
if [ "$current_pos" -gt 0 ]; then
|
||||||
return
|
current_word=${words[${#words[@]}-1]};
|
||||||
fi
|
if [ -n "$line" -a "$line" != "${line%% }" ] ; then
|
||||||
|
|
||||||
local current_word=${words[${#words[@]}-1]};
|
|
||||||
if [ "$line" != "${line%% }" ] ; then
|
|
||||||
nux.log debug "Creating proposal for next word."
|
nux.log debug "Creating proposal for next word."
|
||||||
let current_pos=current_pos+1
|
let current_pos=current_pos+1
|
||||||
current_word=""
|
current_word=""
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
local result="";
|
local result="";
|
||||||
if [ $current_pos -eq 1 ] ; then
|
if [ $current_pos -le 1 ] ; then
|
||||||
result=$(nuxr.tasks.runtime.search $current_word)
|
result=$(nuxr.tasks.runtime.search $current_word | grep -v "help\\.")
|
||||||
elif [ $current_pos -ge 2 ]; then
|
elif [ $current_pos -ge 2 ]; then
|
||||||
command=${words[0]}
|
command=${words[0]}
|
||||||
nux.log debug "Trying to use completer for '$command'"
|
nux.log debug "Trying to use completer for '$command'"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue