mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: Added docs & shorthands for error testing.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
6ec235ce19
commit
91cb61527f
2 changed files with 102 additions and 8 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
link.entered() {
|
link.entered() {
|
||||||
nux.log debug "Testing '$abs_path' as link"
|
nux.log debug "Testing '$abs_path' as link"
|
||||||
if test ! -h "$abs_path"; then
|
if test ! -h "$abs_path"; then
|
||||||
nuxfs.error "$rel_path" "is not symlink."
|
.error "is not symlink."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local REAL_LINK=$(readlink "$abs_path")
|
local REAL_LINK=$(readlink "$abs_path")
|
||||||
|
|
@ -13,26 +13,26 @@ link.entered() {
|
||||||
local cdir=$(dirname "$abs_path")
|
local cdir=$(dirname "$abs_path")
|
||||||
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 "$rel_path" "is using different definition for target '$3'"
|
.warning "is using different definition for target '$3'"
|
||||||
else
|
else
|
||||||
nuxfs.error "$rel_path" "links to $REAL_LINK instead of $target"
|
.error "links to $REAL_LINK instead of $target"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test ! -e "$abs_path"; then
|
if test ! -e "$abs_path"; then
|
||||||
nuxfs.warning "$rel_path" "target '$NC_White$target$NC_No' does not exists."
|
.warning "target '$NC_White$target$NC_No' does not exists."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
git.entered() {
|
git.entered() {
|
||||||
nux.log debug "Testing '$rel_path' as git repository"
|
nux.log debug "Testing '$rel_path' as git repository"
|
||||||
if test ! -e "$rel_path/.git"; then
|
if test ! -e "$rel_path/.git"; then
|
||||||
nuxfs.error "$rel_path" "is not git repository"
|
.error "$rel_path" "is not git repository"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local remotes=$(grep "$origin" "$rel_path/.git/config" | wc -l)
|
local remotes=$(grep "$origin" "$rel_path/.git/config" | wc -l)
|
||||||
if [ $remotes -eq 0 ]; then
|
if [ $remotes -eq 0 ]; then
|
||||||
nuxfs.error "$rel_path" "Does not refer git remote '$origin'"
|
.error "$rel_path" "Does not refer git remote '$origin'"
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,69 @@
|
||||||
#/bin/sh
|
#/bin/sh
|
||||||
|
|
||||||
|
## # NUXFS Domain Specific Language
|
||||||
|
##
|
||||||
|
## *nuxfs* command has its own DSL to describe rules and structure of filesystem
|
||||||
|
## and content of files. It uses file structure definition present in *.nuxfs*
|
||||||
|
## file to understand intented state of directory / filesystem of user.
|
||||||
|
##
|
||||||
|
## This definition is not only used to create filesystem hierarchy, checkout git
|
||||||
|
## repositories but also to verify state of filesystem afterwards.
|
||||||
|
##
|
||||||
|
## ## Example of .nuxfs file in home directory
|
||||||
|
##
|
||||||
|
## *dir* github
|
||||||
|
## *git* nux-env https://github.com/tonydamage/nux-env.git
|
||||||
|
## *git* bats https://github.com/sstephenson/bats.git
|
||||||
|
## *enddir*
|
||||||
|
## *link* .bashrc github/nux-env/bashrc
|
||||||
|
##
|
||||||
|
## This *.nuxfs* file describes simple home structure. When *nuxfs apply*
|
||||||
|
## is executed in folder containing this file, it is equivalent of executing
|
||||||
|
## following commands:
|
||||||
|
##
|
||||||
|
## mkdir -p github
|
||||||
|
## git clone https://github.com/tonydamage/nux-env.git github/nux-env
|
||||||
|
## git clone https://github.com/sstephenson/bats.git
|
||||||
|
## ln -s github/nux-env/bashrc .bashrc
|
||||||
|
##
|
||||||
|
## If we manually remove *github/bats* directory and run *nuxfs check* afterwards
|
||||||
|
## the *github/bats* directory will be reported as missing.
|
||||||
|
##
|
||||||
|
## If we execute *nuxfs apply*, only missing *github/bats* will be cloned.
|
||||||
|
##
|
||||||
|
## # Available Keywords
|
||||||
|
|
||||||
|
## dir <name>
|
||||||
|
## Block keyword which defines directory with specified *name*.
|
||||||
|
## All subsequent keywords represent nested items in these directory
|
||||||
|
## unless **enddir** keyword is encountered.
|
||||||
|
##
|
||||||
.block dir name
|
.block dir name
|
||||||
|
|
||||||
|
## link <name> <target>
|
||||||
|
## Defines a symbolik link with specified *name*, which points to
|
||||||
|
## specified target
|
||||||
|
##
|
||||||
.keyword link name target
|
.keyword link name target
|
||||||
|
|
||||||
|
## git <name> <origin>
|
||||||
|
## Defines an existence of folder with specified *name*, which
|
||||||
|
## is git repository clone of specified *origin*
|
||||||
|
##
|
||||||
.keyword git name origin
|
.keyword git name origin
|
||||||
|
|
||||||
.keyword origin
|
.keyword origin
|
||||||
.keyword name name
|
.keyword name name
|
||||||
.keyword template
|
.keyword template
|
||||||
.keyword exists
|
|
||||||
|
## exists <name>
|
||||||
|
## Defines an existence of file with specified *name*.
|
||||||
|
## When *nuxfs check* is executed absence of this file would result
|
||||||
|
## into error report.
|
||||||
|
##
|
||||||
|
.keyword exists name
|
||||||
|
|
||||||
|
##
|
||||||
.keyword should-not-exists
|
.keyword should-not-exists
|
||||||
|
|
||||||
directory() {
|
directory() {
|
||||||
|
|
@ -17,6 +74,43 @@ sdir() {
|
||||||
dir "$@"
|
dir "$@"
|
||||||
enddir
|
enddir
|
||||||
}
|
}
|
||||||
|
##
|
||||||
|
## #Using custom keywords
|
||||||
|
##
|
||||||
|
## *nuxfs* allows for addition of custom directory specific keywords,
|
||||||
|
## since it is based on *nuxdsl* library.
|
||||||
|
##
|
||||||
|
## FIXME: Describe how to add keywords
|
||||||
|
##
|
||||||
|
.info() {
|
||||||
|
nux.dsl.info "$rel_path" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning() {
|
||||||
|
nux.dsl.warning "$rel_path" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
.error() {
|
||||||
|
nux.dsl.error "$rel_path" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
.should.eq() {
|
||||||
|
local actual="$1"
|
||||||
|
local expected="$2"
|
||||||
|
shift;shift;
|
||||||
|
if [ "$actual" != "$expected" ]; then
|
||||||
|
.warning "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
.must.eq() {
|
||||||
|
local actual="$1"
|
||||||
|
local expected="$2"
|
||||||
|
shift;shift;
|
||||||
|
if [ "$actual" != "$expected" ]; then
|
||||||
|
.error "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
.allways.preprocess() {
|
.allways.preprocess() {
|
||||||
abs_path=$(realpath -Lms "$NUXFS_DEF_DIR/$path");
|
abs_path=$(realpath -Lms "$NUXFS_DEF_DIR/$path");
|
||||||
|
|
@ -31,7 +125,7 @@ sdir() {
|
||||||
|
|
||||||
.check.failed() {
|
.check.failed() {
|
||||||
if [ -z "$NUXFS_IGNORE_MISSING" ]; then
|
if [ -z "$NUXFS_IGNORE_MISSING" ]; then
|
||||||
nux.dsl.error "$rel_path" does not exists.
|
.error does not exists.
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
dir.entered() {
|
dir.entered() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue