mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Improved help system.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
ff4e509d1c
commit
89010fd209
9 changed files with 233 additions and 133 deletions
|
|
@ -39,6 +39,11 @@
|
|||
## unless **enddir** keyword is encountered.
|
||||
##
|
||||
.block dir name
|
||||
dir.entered() {
|
||||
if nux.check.file.exists "$abs_path/.nuxfs"; then
|
||||
source "$abs_path/.nuxfs"
|
||||
fi
|
||||
}
|
||||
|
||||
## link <name> <target>
|
||||
## Defines a symbolik link with specified *name*, which points to
|
||||
|
|
@ -63,8 +68,24 @@
|
|||
##
|
||||
.keyword exists name
|
||||
|
||||
## should-not-exists <match>
|
||||
## Defines a requirement for file not to be present.
|
||||
## *nuxfs check*: error will be raised if file exists.
|
||||
## *nuxfs fix*: files which match the match will be deleted.
|
||||
##
|
||||
.keyword should-not-exists
|
||||
##
|
||||
.keyword should-not-exists match
|
||||
should-not-exists.check() {
|
||||
test $(find "$(dirname "$abs_path")" -maxdepth 1 -iname "$match" | wc -l) -eq 0
|
||||
}
|
||||
|
||||
should-not-exists.check.failed() {
|
||||
find "$(dirname "$rel_path")" -maxdepth 1 -iname "$match" | while read f
|
||||
do
|
||||
nux.dsl.error $f Should not exists, but is present.
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
.keyword cathegorize match min delimiter
|
||||
cathegorize.check() {
|
||||
|
|
@ -129,6 +150,7 @@ sdir() {
|
|||
dir "$@"
|
||||
enddir
|
||||
}
|
||||
|
||||
##
|
||||
## #Using custom keywords
|
||||
##
|
||||
|
|
@ -183,22 +205,3 @@ sdir() {
|
|||
.error does not exists.
|
||||
fi
|
||||
}
|
||||
dir.entered() {
|
||||
if nux.check.file.exists "$abs_path/.nuxfs"; then
|
||||
source "$abs_path/.nuxfs"
|
||||
fi
|
||||
}
|
||||
|
||||
should-not-exists.check() {
|
||||
nux.log trace "Checking existence of $NC_White$abs_path$NC_No"
|
||||
if nux.check.file.exists "$abs_path"; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
should-not-exists.check.failed() {
|
||||
for f in "$rel_path"; do
|
||||
nux.dsl.error $f Should not exists, but is present.
|
||||
done
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
.use-dsl nuxfs.apply
|
||||
|
||||
should-not-exists.check.failed() {
|
||||
for f in "$rel_path"; do
|
||||
rm -r "$f"
|
||||
nux.dsl.info $f Deleted.
|
||||
done
|
||||
find "$(dirname "$rel_path")" -maxdepth 1 -iname "$id" -delete
|
||||
}
|
||||
|
||||
cathegorize.process.file() {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ NC_LOG_id_trace=5
|
|||
## debug
|
||||
## trace
|
||||
##
|
||||
## nux.log <level> <message>
|
||||
## nux.log:: <level> <message>
|
||||
## Outputs log message to *STDERR*. LOG messages are filtered out based on
|
||||
## level. Use *nux.log.level* to specify which messages should be displayed.
|
||||
##
|
||||
|
|
@ -91,7 +91,7 @@ function nux.log {
|
|||
}
|
||||
|
||||
|
||||
## nux.log.level <level>
|
||||
## nux.log.level:: <level>
|
||||
## Sets maximum level of details to be logged.
|
||||
##
|
||||
function nux.log.level {
|
||||
|
|
@ -108,8 +108,7 @@ function nux.echo.warning {
|
|||
echo -e "${NC_warning}"$@" ${NC_No}";
|
||||
}
|
||||
|
||||
## nux.use <library>
|
||||
##
|
||||
## nux.use:: <library>
|
||||
function nux.use {
|
||||
local incfile="$1.inc.sh"
|
||||
source "$NUX_INC_DIR/$incfile"
|
||||
|
|
@ -120,7 +119,12 @@ function nux.fatal {
|
|||
exit -1;
|
||||
}
|
||||
|
||||
## nux.require <binary> [<common-package>]
|
||||
## nux.notimplemented:: <feature-id>
|
||||
function nux.notimplemented {
|
||||
nux.fatal "$@: is not imlemented."
|
||||
}
|
||||
|
||||
## nux.require:: <binary> [<common-package>]
|
||||
function nux.require {
|
||||
local binary=$1;
|
||||
local package=${2:-$1}
|
||||
|
|
@ -137,9 +141,10 @@ function nux.include {
|
|||
source "$NUX_INC_DIR/$incfile"
|
||||
}
|
||||
|
||||
## nux.check.function <name>
|
||||
## nux.check.function:: <name>
|
||||
##
|
||||
function nux.check.function {
|
||||
nux.log trace "Checking if $1 is function."
|
||||
declare -f "$1" &>/dev/null && return 0
|
||||
return 1
|
||||
}
|
||||
|
|
@ -149,7 +154,7 @@ function nux.check.exec {
|
|||
test -n "$(which "$binary")"
|
||||
}
|
||||
|
||||
## nux.check.file.exists <name>
|
||||
## nux.check.file.exists:: <name>
|
||||
##
|
||||
function nux.check.file.exists {
|
||||
test -e "$1" -o -h "$1";
|
||||
|
|
@ -160,7 +165,7 @@ function nux.eval {
|
|||
eval "$@"
|
||||
}
|
||||
|
||||
## nux.exec.optional <name> [<arguments>]
|
||||
## nux.exec.optional:: <name> [<arguments>]
|
||||
##
|
||||
function nux.exec.optional {
|
||||
local FUNC="$1"; shift;
|
||||
|
|
@ -176,21 +181,22 @@ function nux.dirty.urlencode {
|
|||
|
||||
function nux.help.comment {
|
||||
local source="$1"
|
||||
grep -E "^\#\#( |$)" "$source" \
|
||||
| cut -d\# -f3- \
|
||||
| cut -d" " -f2- \
|
||||
| nux.help.shelldoc
|
||||
|
||||
if nux.check.file.exists "$source" ; then
|
||||
grep -E "^\#\#( |$)" "$source" \
|
||||
| cut -d\# -f3- \
|
||||
| cut -d" " -f2- \
|
||||
| nux.help.shelldoc
|
||||
fi
|
||||
}
|
||||
|
||||
function nux.help.shelldoc {
|
||||
cat | sed -r \
|
||||
sed -r \
|
||||
-e "s/^## ?(.*)/${NC_White}\1${NC_No}/gI" \
|
||||
-e "s/^# ?(.*)/${NC_Bold}\1${NC_No}/gI" \
|
||||
-e "s/^ ?[a-z0-9.-_]*/${NC_Bold}&${NC_No}/gI" \
|
||||
-e "s/^([ a-z0-9.-_]*)::/${NC_Bold}\1${NC_No}/gI" \
|
||||
-e "s/\*\*([^*]*)\*\*/${NC_Bold}\1${NC_No}/gI" \
|
||||
-e "s/\*([^*]*)\*/${NC_White}\1${NC_No}/gI" \
|
||||
|
||||
--
|
||||
}
|
||||
|
||||
function nux.url.parse {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,53 @@
|
|||
|
||||
|
||||
nux-runner.run() {
|
||||
nuxr.run() {
|
||||
TASK=$1; shift; # Determines task
|
||||
if nux.check.function task.$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
|
||||
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
|
||||
fi
|
||||
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
|
||||
echo "Try '$NUX_SCRIPTNAME help' for more information."
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
function nuxr.task.help {
|
||||
command="$1"
|
||||
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\>]
|
||||
nux.help.comment "$NUX_SCRIPT"
|
||||
nux.help.comment "$NUX_RUNNER"
|
||||
nux.exec.optional task.help.additional
|
||||
elif nux.check.function "task.help.$command" ; then
|
||||
shift;
|
||||
task.help.$command "$@";
|
||||
else
|
||||
nuxr.help.task.comment "$NUX_SCRIPT" "$command" \
|
||||
|| nuxr.help.task.comment "$NUX_RUNNER" "$command" \
|
||||
|| echo "Help topic $1 not found. Run $0 help to see topics."
|
||||
fi
|
||||
}
|
||||
|
||||
function nuxr.help.task.comment {
|
||||
local script="$1"
|
||||
local task="$2"
|
||||
|
||||
nux.log trace "Trying to figure task documentation location for $@"
|
||||
doc_start=$(grep -hn -E "## +($task)::" "$script" | cut -d: -f1)
|
||||
code_start=$(grep -hn -E "((function +task.$task)|(task.$task *\(\))) +{" "$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" \
|
||||
| grep "^\#\#" \
|
||||
| sed -re "s/^#+ ?(.*)/\1/gi" \
|
||||
| nux.help.shelldoc
|
||||
return 0
|
||||
else
|
||||
return -1
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,14 @@ function nux.cfg.include {
|
|||
}
|
||||
|
||||
##
|
||||
## nux.cfg.global.path [<path>]
|
||||
## nux.cfg.global.path
|
||||
## Returns global path., otherwise provides specified.
|
||||
##
|
||||
function nux.cfg.global.path {
|
||||
function nux.cfg.global.dir {
|
||||
:
|
||||
}
|
||||
|
||||
function nux.cfg.dist.dir
|
||||
:
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue