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

Fixed help generation

This commit is contained in:
Tony Tkáčik 2024-03-28 12:10:57 +01:00
parent d3ca4e1b9a
commit a8f9415ba1
3 changed files with 13 additions and 15 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env nuxr-nuxsh #!/usr/bin/env nuxsh
## Portable *nix environment by tonydamage ## Portable *nix environment by tonydamage
## ##

View file

@ -1,9 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
### ###
### *nuxr-nuxsh* is wrapped bash interpreter for *nux-env* enhanced bash scripts ### *nuxr-nuxsh* and *nuxsh* is wrapped bash interpreter for *nux-env* enhanced
### and provides out of the box support for command-style scripts (similar in ### bash scripts.
### usage such as apt, git) with following features out of the box: ### It provides out of the box support for command-style scripts
### (similar in usage such as apt, git) with following features out of the box:
### ###
### task selection:: ### task selection::
### Automaticly selects correct tasks, displays help if ### Automaticly selects correct tasks, displays help if
@ -25,7 +26,7 @@
### ###
### ###
### 1. Shebang:: ### 1. Shebang::
### Shebang (*#!*) at the start of file is *#!/usr/bin/env nuxr-nuxsh* ### Shebang (*#!*) at the start of file is *#!/usr/bin/env nuxsh*
### 2. Tasks:: ### 2. Tasks::
### Script usually does only defines functions in form task {taskname} ### Script usually does only defines functions in form task {taskname}
### where taskname ### where taskname
@ -44,13 +45,10 @@ nux.use nuxr
nux.use nux.cfg nux.use nux.cfg
## ##
## Additional commands provided by *nux-runner*: ## Additional commands provided by *nuxsh*:
### *nux-runner* automaticly provides following tasks to any script it executes: ### *nuxsh* automaticly provides following tasks to any script it executes:
## ##
## debug:: <task> [<task arguments>] ## debug:: <task> [<task arguments>]
## Runs specified task with debug messages enabled. ## Runs specified task with debug messages enabled.
task.debug() { task.debug() {
@ -70,6 +68,7 @@ task.trace() {
## documentation. ## documentation.
task.help() { task.help() {
nuxr.task.help "$@" nuxr.task.help "$@"
echo
} }
## config:: [type] name [value] ## config:: [type] name [value]
@ -158,9 +157,8 @@ if [ -n "$NUX_SCRIPT" ]; then
nuxr.main "$@" nuxr.main "$@"
else else
echo Usage: nuxsh [script] [command] [options]
echo Usage: nux-runner [script] [task] [options]
echo echo
grep "^\#\#" "$NUX_RUNNER" | sed -re "s/^#+ ?(.*)/\1/gi" | nux.help.shelldoc nux.help.comment "$NUX_RUNNER"
echo echo
fi fi

View file

@ -1,5 +1,6 @@
nux.use nux/color nux.use nux/color
nux.use nuxr/repl nux.use nuxr/repl
nux.use nux/help
@prefix check nux.check. @prefix check nux.check.
@prefix help nux.help. @prefix help nux.help.
@ -50,7 +51,6 @@ nux.use nuxr/repl
@namespace nuxr.task.help. { @namespace nuxr.task.help. {
function : { function : {
nux.use nux/help
allArgs="$@" allArgs="$@"
if [ -z "$allArgs" ] { if [ -z "$allArgs" ] {
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\>]
@ -85,7 +85,7 @@ nux.use nuxr/repl
local task_dot=$(tr " " "." <<< "$task") local task_dot=$(tr " " "." <<< "$task")
nux.log trace "Trying to figure task documentation location for $task $task_dot" 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 "((@command +:?$task_dot)|(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 nux.log trace "doc_start" $doc_start $code_start
if [ -n "$doc_start" -a -n "$code_start" ] { if [ -n "$doc_start" -a -n "$code_start" ] {
sed -n "$doc_start,$code_start"p "$script" \ sed -n "$doc_start,$code_start"p "$script" \