diff --git a/bin/nuxfs b/bin/nuxfs index 9ac6781..afc265f 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -10,93 +10,24 @@ local TEMPLATE_FILTER="*$SUFFIX" nux.use nux.dsl nux.use nuxfs + GIT_BIN=$(which git) -nux.fs.dsl() { - .block dir - .keyword link - .keyword git - .keyword origin - .keyword name - .keyword template - - sdir() { - dir "$@" - enddir - } - - .preprocess() { - abs_path=$NUXFS_DEF_DIR/$path; - rel_path=$(realpath -m -s "$abs_path" --relative-base="$WORKDIR"); - } - - .check() { - nux.check.file.exists "$abs_path" - } - - .check.failed() { - nux.dsl.error "$rel_path" does not exists. - } -} - task.check() { - link.entered() { - nux.log debug "Testing '$rel_path' as link" - if test ! -h "$abs_path"; then - nuxfs.error "$rel_path" "is not symlink." - return - fi - local REAL_LINK=$(readlink "$abs_path") - local TARGET="$3"; - if test ! "$REAL_LINK" = "$TARGET"; then - MAT_REAL=$(realpath "$REAL_LINK") - local cdir=$(dirname "$abs_path") - MAT_TARGET=$(realpath "$cdir/$TARGET") - if test "$MAT_REAL" = "$MAT_TARGET"; then - nuxfs.warning "$rel_path" "is using different definition for target '$3'" - else - nuxfs.error "$rel_path" "links to $REAL_LINK instead of $TARGET" - return - fi - fi - if test ! -e "$1"; then - nuxfs.warning "$rel_path" "target '$NC_White$2$NC_No' does not exists." - fi - } - git.entered() { - nux.log debug "Testing '$rel_path' as git repository" - if test ! -e "$1/.git"; then - nuxfs.error "$rel_path" "is not git repository" - return - fi - local remotes=$(grep "$3" "$rel_path/.git/config" | wc -l) - if [ $remotes -eq 0 ]; then - nuxfs.error "$rel_path" "Does not refer git remote '$3'" - return; - fi - } - process "$@"; + nuxfs.dsl.process "$@"; } +task.describe() { + nuxfs.dsl.process "$@"; +} + + ## apply - Creates missing files as described in nuxfs definition. task.apply() { - dir.check.recover() { - nuxfs.info "$rel_path" "Created directory"; - mkdir -p "$abs_path" - } - link.check.recover() { - nuxfs.info "$rel_path" "Creating link to '$3'"; - ln -s "$3" "$abs_path" - } - git.check.recover() { - $GIT_BIN clone "$3" "$abs_path" - } - process "$@"; + nuxfs.dsl.process "$@"; } -nux.dsl.load nux.fs.dsl - -process() { +nuxfs.dsl.process() { WORKDIR=$(pwd); TARGET=$1; if [ -n "$TARGET" ]; then @@ -130,7 +61,7 @@ process() { if test -e "$NUXFS_DEF"; then # #NUXFS_TARGET_FOUND=0; - source "$NUXFS_DEF"; + nux.dsl.execute "$NUX_INC_DIR/dsl/nuxfs.$TASK" "$NUXFS_DEF"; # #if [ $NUXFS_TARGET_FOUND = 0 ]; then # # nuxfs.warning "$3" "Does not have definition in $DEF"; @@ -176,7 +107,6 @@ function task.init { # function task.template { nux.log debug $NUX_ENV_DIR - nuxfs.template.list } diff --git a/inc/dsl/nuxfs.apply.dsl b/inc/dsl/nuxfs.apply.dsl new file mode 100644 index 0000000..bb127a5 --- /dev/null +++ b/inc/dsl/nuxfs.apply.dsl @@ -0,0 +1,13 @@ +.use-dsl nuxfs + +dir.check.recover() { + nuxfs.info "$rel_path" "Created directory"; + mkdir -p "$abs_path" +} +link.check.recover() { + nuxfs.info "$rel_path" "Creating link to '$3'"; + ln -s "$3" "$abs_path" +} +git.check.recover() { + $GIT_BIN clone "$3" "$abs_path" +} diff --git a/inc/dsl/nuxfs.check.dsl b/inc/dsl/nuxfs.check.dsl new file mode 100644 index 0000000..4e6920c --- /dev/null +++ b/inc/dsl/nuxfs.check.dsl @@ -0,0 +1,39 @@ +.use-dsl nuxfs + +link.entered() { + nux.log debug "Testing '$abs_path' as link" + if test ! -h "$abs_path"; then + nuxfs.error "$rel_path" "is not symlink." + return + fi + local REAL_LINK=$(readlink "$abs_path") + local TARGET="$3"; + nux.log trace "Target is: $TARGET, real link: $REAL_LINK" + if test ! "$REAL_LINK" = "$TARGET"; then + MAT_REAL=$(realpath "$REAL_LINK") + local cdir=$(dirname "$abs_path") + MAT_TARGET=$(realpath "$cdir/$TARGET") + if test "$MAT_REAL" = "$MAT_TARGET"; then + nuxfs.warning "$rel_path" "is using different definition for target '$3'" + else + nuxfs.error "$rel_path" "links to $REAL_LINK instead of $TARGET" + return + fi + fi + if test ! -e "$abs_path"; then + nuxfs.warning "$rel_path" "target '$NC_White$TARGET$NC_No' does not exists." + fi +} + +git.entered() { + nux.log debug "Testing '$rel_path' as git repository" + if test ! -e "$rel_path/.git"; then + nuxfs.error "$rel_path" "is not git repository" + return + fi + local remotes=$(grep "$3" "$rel_path/.git/config" | wc -l) + if [ $remotes -eq 0 ]; then + nuxfs.error "$rel_path" "Does not refer git remote '$3'" + return; + fi +} diff --git a/inc/dsl/nuxfs.describe.dsl b/inc/dsl/nuxfs.describe.dsl new file mode 100644 index 0000000..39b6e56 --- /dev/null +++ b/inc/dsl/nuxfs.describe.dsl @@ -0,0 +1,5 @@ +.use-dsl nuxfs + +.entered() { + nux.dsl.info "$rel_path" $keyword +} diff --git a/inc/dsl/nuxfs.dsl b/inc/dsl/nuxfs.dsl new file mode 100644 index 0000000..5344de9 --- /dev/null +++ b/inc/dsl/nuxfs.dsl @@ -0,0 +1,35 @@ +.block dir name +.keyword link name target +.keyword git name origin +.keyword origin +.keyword name name +.keyword template +.keyword exists + +directory() { + dir +} + +sdir() { + dir "$@" + enddir +} + +.allways.preprocess() { + abs_path=$(realpath -Lms "$NUXFS_DEF_DIR/$path"); + rel_path=$(realpath -Lms "$abs_path" --relative-base="$WORKDIR"); +} + +.check() { + nux.log trace "Checking existence of $NC_White$abs_path$NC_No" + nux.check.file.exists "$abs_path" +} + +.check.failed() { + nux.dsl.error "$abs_path" does not exists. +} +dir.entered() { + if nux.check.file.exists "$abs_path/.nuxfs"; then + source "$abs_path/.nuxfs" + fi +}