From fbf020f0d3481aa96924c762938f49b9ae78748d Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 28 Nov 2016 16:13:21 +0100 Subject: [PATCH] nuxfs: Added support for specifying path. Signed-off-by: Tony Tkacik --- bin/nuxfs | 21 +++++++++++++++------ inc/nuxfs.dsl.inc.sh | 8 ++++++++ inc/nuxfs.inc.sh | 12 ++++++++---- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/bin/nuxfs b/bin/nuxfs index 6bb7a56..9978eee 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -51,7 +51,7 @@ function task.check { def.notexists() { nuxfs.error "$1" "does not exists". } - nuxfs.initcfg + nuxfs.initcfg "$@" nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE" } @@ -76,7 +76,7 @@ function task.apply { popd > /dev/null; } - nuxfs.initcfg + nuxfs.initcfg "$@" nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE" } @@ -152,14 +152,23 @@ function nuxfs.template.list { function nuxfs.initcfg { - WORKDIR=$(pwd); - NUXFS_DEF=$(nuxfs.closest $SUFFIX); + WORKDIR=$1; + if [ -n "$WORKDIR" ]; then + WORKDIR=$WORKDIR + else + WORKDIR=$(pwd); + fi; + + nux.log debug Target: $WORKDIR + + NUXFS_DEF=$(nuxfs.closest $SUFFIX "$WORKDIR"); if [ "$NUXFS_DEF" = "" ]; then nuxfs.error $(pwd) "No nuxfs configuration found." return; fi; NUXFS_DEF_DIR=$(dirname $NUXFS_DEF); - WORKDIR_RELATIVE=$(realpath "$WORKDIR" --relative-to "$NUXFS_DEF_DIR") - WORKDIR_ABSOLUTE=$(realpath "$WORKDIR") + WORKDIR_RELATIVE=$(realpath -ms "$WORKDIR" --relative-to "$NUXFS_DEF_DIR") + WORKDIR_ABSOLUTE=$(realpath -ms "$WORKDIR") + } diff --git a/inc/nuxfs.dsl.inc.sh b/inc/nuxfs.dsl.inc.sh index 700b24d..bcbd0e2 100644 --- a/inc/nuxfs.dsl.inc.sh +++ b/inc/nuxfs.dsl.inc.sh @@ -31,6 +31,10 @@ function nuxfs.dsl.command { if [[ "$NESTED_DIR" = "$localFile"* || "$localFile" = "$NESTED_DIR"* ]]; then nux.log debug $localFile is affected by $NESTED_DIR; + if [[ "$NESTED_DIR" = "$localFile/" || "$localFile" = "$NESTED_DIR"* ]]; then + NUXFS_TARGET_FOUND=1; + fi + if nuxfs.file.exists "$localFile"; then nux.log debug "File $NC_White$localFile$NC_No exits"; exec.if.function $CMD.exists def.exists "$localFile" "$@"; @@ -102,7 +106,11 @@ function nuxfs.dsl.execute { declare -a DIR_ARRAY DIR_ARRAY[0]=$DIR if test -e "$DEF"; then + NUXFS_TARGET_FOUND=0; source "$DEF"; + if [ $NUXFS_TARGET_FOUND = 0 ]; then + nuxfs.warning "$3" "Does not have definition in $DEF"; + fi else nuxfs.error "$DEF" Definition file does not exists. fi diff --git a/inc/nuxfs.inc.sh b/inc/nuxfs.inc.sh index bb357dc..cb90956 100644 --- a/inc/nuxfs.inc.sh +++ b/inc/nuxfs.inc.sh @@ -2,18 +2,22 @@ function nuxfs.relative { echo "$(nuxfs.dir.get)/$1" } +function nuxfs.relative-to-pwd { + realpath -s "$1" --relative-to "$(realpath "$(pwd)")" +} + function nuxfs.error { - local filename=$1; shift; + local filename=$(nuxfs.relative-to-pwd "$1"); shift; nux.echo.error "$filename"$NC_No: $*; } function nuxfs.warning { - local filename=$1; shift; + local filename=$(nuxfs.relative-to-pwd "$1"); shift; nux.echo.warning "$filename"$NC_No: $*; } function nuxfs.info { - local filename=$1; shift; + local filename=$(nuxfs.relative-to-pwd "$1"); shift; echo -e $NC_White"$filename"$NC_No: $*; } @@ -36,7 +40,7 @@ function nuxfs.file.exists { function nuxfs.closest { cmd=$1; - cdir=$(pwd); + cdir=$2; nux.log trace "Searching in: " $cdir; until [ -e "$cdir/$1" -o "$cdir" == "/" ]; do cdir=$(dirname "$cdir");