mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: Added support for invoking in nested dir.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
850bf0d339
commit
d40b82bfc8
3 changed files with 50 additions and 12 deletions
23
bin/nuxfs
23
bin/nuxfs
|
|
@ -26,7 +26,7 @@ function task.verify {
|
||||||
local cdir=$(dirname "$1")
|
local cdir=$(dirname "$1")
|
||||||
MAT_TARGET=$(realpath "$cdir/$TARGET")
|
MAT_TARGET=$(realpath "$cdir/$TARGET")
|
||||||
if test "$MAT_REAL" = "$MAT_TARGET"; then
|
if test "$MAT_REAL" = "$MAT_TARGET"; then
|
||||||
nuxfs.warning "$1" "links to target '$2', but is using different definition."
|
nuxfs.warning "$1" "is using different definition for target '$2'"
|
||||||
else
|
else
|
||||||
nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET"
|
nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET"
|
||||||
return
|
return
|
||||||
|
|
@ -51,7 +51,8 @@ function task.verify {
|
||||||
def.notexists() {
|
def.notexists() {
|
||||||
nuxfs.error "$1" "does not exists".
|
nuxfs.error "$1" "does not exists".
|
||||||
}
|
}
|
||||||
nuxfs.dsl.execute .nuxfs
|
nuxfs.initcfg
|
||||||
|
nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE"
|
||||||
}
|
}
|
||||||
|
|
||||||
## create - Creates missing files as described in nuxfs definition.
|
## create - Creates missing files as described in nuxfs definition.
|
||||||
|
|
@ -75,7 +76,8 @@ function task.create {
|
||||||
popd > /dev/null;
|
popd > /dev/null;
|
||||||
}
|
}
|
||||||
|
|
||||||
nuxfs.dsl.execute $SUFFIX
|
nuxfs.initcfg
|
||||||
|
nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE"
|
||||||
}
|
}
|
||||||
|
|
||||||
## init - Initializes a directory using template
|
## init - Initializes a directory using template
|
||||||
|
|
@ -129,3 +131,18 @@ function nuxfs.template.list {
|
||||||
done;
|
done;
|
||||||
popd > /dev/null;
|
popd > /dev/null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function nuxfs.initcfg {
|
||||||
|
|
||||||
|
WORKDIR=$(pwd);
|
||||||
|
NUXFS_DEF=$(nuxfs.closest $SUFFIX);
|
||||||
|
|
||||||
|
if [ "$NUXFS_DEF" = "" ]; then
|
||||||
|
nuxfs.error $(pwd) "No nuxfs configuration found."
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
NUXFS_DEF_DIR=$(dirname $NUXFS_DEF);
|
||||||
|
WORKDIR_RELATIVE=$(realpath "$WORKDIR" --relative-to "$NUXFS_DEF_DIR")
|
||||||
|
WORKDIR_ABSOLUTE=$(realpath "$WORKDIR")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,23 @@ function exec.if.function {
|
||||||
function nuxfs.dsl.command {
|
function nuxfs.dsl.command {
|
||||||
CMD=$1;
|
CMD=$1;
|
||||||
localFile=$(nuxfs.relative "$2");
|
localFile=$(nuxfs.relative "$2");
|
||||||
shift; shift;
|
|
||||||
|
|
||||||
nux.log debug Processing $CMD "$localFile" $@;
|
|
||||||
|
shift; shift;
|
||||||
|
nux.log trace Processing $CMD "$localFile" $@;
|
||||||
|
|
||||||
exec.if.function $CMD.pre def.pre "$localFile" "$@";
|
exec.if.function $CMD.pre def.pre "$localFile" "$@";
|
||||||
|
|
||||||
nux.log debug Working file: $NC_White$localFile;
|
if [[ "$NESTED_DIR" = "$localFile"* || "$localFile" = "$NESTED_DIR"* ]]; then
|
||||||
|
nux.log debug $localFile is affected by $NESTED_DIR;
|
||||||
|
|
||||||
if nuxfs.file.exists "$localFile"; then
|
if nuxfs.file.exists "$localFile"; then
|
||||||
nux.log debug "File $localFile exits";
|
nux.log debug "File $NC_White$localFile$NC_No exits";
|
||||||
exec.if.function $CMD.exists def.exists "$localFile" "$@";
|
exec.if.function $CMD.exists def.exists "$localFile" "$@";
|
||||||
else
|
else
|
||||||
nux.log debug "File $localFile does not exists";
|
nux.log debug "File $NC_White$localFile$NC_No does not exists";
|
||||||
exec.if.function $CMD.notexists def.notexists "$localFile" "$@";
|
exec.if.function $CMD.notexists def.notexists "$localFile" "$@";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
exec.if.function $CMD.post def.post "$localFile" "$@";
|
exec.if.function $CMD.post def.post "$localFile" "$@";
|
||||||
}
|
}
|
||||||
|
|
@ -91,11 +95,15 @@ function nuxfs.dsl.keywords {
|
||||||
|
|
||||||
function nuxfs.dsl.execute {
|
function nuxfs.dsl.execute {
|
||||||
nuxfs.dsl.keywords
|
nuxfs.dsl.keywords
|
||||||
|
local DEF="$1";
|
||||||
|
local DIR="$2";
|
||||||
|
NESTED_DIR="$(realpath "$3")/";
|
||||||
|
nux.log debug "Working Directory: $DIR , Nested Directory: $NESTED_DIR"
|
||||||
declare -a DIR_ARRAY
|
declare -a DIR_ARRAY
|
||||||
DIR_ARRAY[0]=.
|
DIR_ARRAY[0]=$DIR
|
||||||
if test -e "$1"; then
|
if test -e "$DEF"; then
|
||||||
source $1;
|
source "$DEF";
|
||||||
else
|
else
|
||||||
nuxfs.error "$1" Definition file does not exists.
|
nuxfs.error "$DEF" Definition file does not exists.
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,16 @@ function nuxfs.dir.push {
|
||||||
function nuxfs.file.exists {
|
function nuxfs.file.exists {
|
||||||
test -e "$1" -o -h "$1";
|
test -e "$1" -o -h "$1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nuxfs.closest {
|
||||||
|
cmd=$1;
|
||||||
|
cdir=$(pwd);
|
||||||
|
nux.log trace "Searching in: " $cdir;
|
||||||
|
until [ -e "$cdir/$1" -o "$cdir" == "/" ]; do
|
||||||
|
cdir=$(dirname "$cdir");
|
||||||
|
nux.log trace "Searching in: " $cdir;
|
||||||
|
done;
|
||||||
|
if [ -e "$cdir/$1" ]; then
|
||||||
|
echo "$cdir/$1";
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue