mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: Added support for custom / folder specific DSL
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
d3be24f3d7
commit
5d69659e3c
5 changed files with 102 additions and 80 deletions
13
inc/dsl/nuxfs.apply.dsl
Normal file
13
inc/dsl/nuxfs.apply.dsl
Normal file
|
|
@ -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"
|
||||
}
|
||||
39
inc/dsl/nuxfs.check.dsl
Normal file
39
inc/dsl/nuxfs.check.dsl
Normal file
|
|
@ -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
|
||||
}
|
||||
5
inc/dsl/nuxfs.describe.dsl
Normal file
5
inc/dsl/nuxfs.describe.dsl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.use-dsl nuxfs
|
||||
|
||||
.entered() {
|
||||
nux.dsl.info "$rel_path" $keyword
|
||||
}
|
||||
35
inc/dsl/nuxfs.dsl
Normal file
35
inc/dsl/nuxfs.dsl
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue