1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

nuxsh: Added support for @command keyword and use it

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2020-01-01 13:12:55 +01:00
parent 27f3986528
commit e148c76fbe
6 changed files with 103 additions and 82 deletions

View file

@ -30,13 +30,19 @@ nux.nuxsh.language.def() {
.match.line block_end '(\})' \
syntax
.match.line if_start "(if)( +)$prefixed_id( +)$args?( *)(\{)" \
keyword indent2 prefix identifier indent3 args - - - - - indent4 syntax3
.match.line task_start "((@command)( +))($identifier)((\()|( *))(($identifier,? *)*)(\))?( *)(\{)" \
- keyword indent2 identifier - syntax indent3 args - syntax2 indent4 syntax3
.match.line function_start "((function)( +))($identifier)((\()|( *))(($identifier,? *)*)(\))?( *)(\{)" \
- keyword indent2 identifier - syntax indent3 args - syntax2 indent4 syntax3
.match.line block_start "($identifier)(( +)$args)?( *)(\{)" \
identifier - indent2 args - - - - - indent3 syntax3
@ -51,12 +57,12 @@ nux.nuxsh.language.def() {
.highlight prefix cyan
.highlight identifier green
.highlight keyword blue
.highlight keyword cyan
.highlight args yellow
.highlight comment magenta
.highlight unmatched red
.highlight unmatched white
.highlight syntax white
.highlight syntax2 white
@ -172,6 +178,20 @@ nux.nuxsh.language.def() {
done
}
.match.task_start.plan() {
.block.push task
case $identifier in
:*) identifier="task.${identifier#:}";;
*) identifier="task.$identifier"
esac;
echo "${indent}$identifier() {";
echo "${indent} nux.log trace $identifier: invoked";
for arg in ${args//,/ }; do
echo "${indent} local $arg="'"$1"'";shift;"
echo "${indent} nux.log trace ' ' arg $arg: "'$'$arg";"
done
}
.block.start.plan() {
case $identifier in
function) echo "$line";;

View file

@ -1,4 +1,3 @@
nux.use nux/color
nux.use nuxr/repl
@ -86,7 +85,7 @@ nux.use nuxr/repl
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_dot)|(task.$task_dot *\(\))) +{" "$script" | cut -d: -f1)
code_start=$(grep -hn -E "((@command +:?$task_dot .*)|(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" ] {
sed -n "$doc_start,$code_start"p "$script" \
@ -96,6 +95,6 @@ nux.use nuxr/repl
return 0
else
return -1
}
}
}
}