mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: Small fixes.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
5d69659e3c
commit
7479fb53f8
6 changed files with 108 additions and 32 deletions
|
|
@ -13,6 +13,7 @@ nux.use nuxfs
|
||||||
|
|
||||||
GIT_BIN=$(which git)
|
GIT_BIN=$(which git)
|
||||||
|
|
||||||
|
## check - Verifies that directory matches nuxfs specification
|
||||||
task.check() {
|
task.check() {
|
||||||
nuxfs.dsl.process "$@";
|
nuxfs.dsl.process "$@";
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +37,8 @@ nuxfs.dsl.process() {
|
||||||
TARGET=$(pwd);
|
TARGET=$(pwd);
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
nux.log debug Target: $TARGET
|
TARGET=$(realpath -Lms "$TARGET")
|
||||||
|
nux.log debug Target: $TARGET
|
||||||
|
|
||||||
NUXFS_DEF=$(nuxfs.closest $SUFFIX "$TARGET");
|
NUXFS_DEF=$(nuxfs.closest $SUFFIX "$TARGET");
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ dir.check.recover() {
|
||||||
}
|
}
|
||||||
link.check.recover() {
|
link.check.recover() {
|
||||||
nuxfs.info "$rel_path" "Creating link to '$3'";
|
nuxfs.info "$rel_path" "Creating link to '$3'";
|
||||||
ln -s "$3" "$abs_path"
|
ln -s "$target" "$abs_path"
|
||||||
}
|
}
|
||||||
git.check.recover() {
|
git.check.recover() {
|
||||||
$GIT_BIN clone "$3" "$abs_path"
|
$GIT_BIN clone "$origin" "$abs_path"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,20 @@ link.entered() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local REAL_LINK=$(readlink "$abs_path")
|
local REAL_LINK=$(readlink "$abs_path")
|
||||||
local TARGET="$3";
|
nux.log trace "Target is: $target, real link: $REAL_LINK"
|
||||||
nux.log trace "Target is: $TARGET, real link: $REAL_LINK"
|
if test ! "$REAL_LINK" = "$target"; then
|
||||||
if test ! "$REAL_LINK" = "$TARGET"; then
|
|
||||||
MAT_REAL=$(realpath "$REAL_LINK")
|
MAT_REAL=$(realpath "$REAL_LINK")
|
||||||
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'"
|
nuxfs.warning "$rel_path" "is using different definition for target '$3'"
|
||||||
else
|
else
|
||||||
nuxfs.error "$rel_path" "links to $REAL_LINK instead of $TARGET"
|
nuxfs.error "$rel_path" "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."
|
nuxfs.warning "$rel_path" "target '$NC_White$target$NC_No' does not exists."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,9 +30,9 @@ git.entered() {
|
||||||
nuxfs.error "$rel_path" "is not git repository"
|
nuxfs.error "$rel_path" "is not git repository"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local remotes=$(grep "$3" "$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 '$3'"
|
nuxfs.error "$rel_path" "Does not refer git remote '$origin'"
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#/bin/sh
|
||||||
|
|
||||||
.block dir name
|
.block dir name
|
||||||
.keyword link name target
|
.keyword link name target
|
||||||
.keyword git name origin
|
.keyword git name origin
|
||||||
|
|
@ -5,6 +7,7 @@
|
||||||
.keyword name name
|
.keyword name name
|
||||||
.keyword template
|
.keyword template
|
||||||
.keyword exists
|
.keyword exists
|
||||||
|
.keyword should-not-exists
|
||||||
|
|
||||||
directory() {
|
directory() {
|
||||||
dir
|
dir
|
||||||
|
|
@ -25,8 +28,22 @@ sdir() {
|
||||||
nux.check.file.exists "$abs_path"
|
nux.check.file.exists "$abs_path"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
should-not-exists.check() {
|
||||||
|
nux.log trace "Checking existence of $NC_White$abs_path$NC_No"
|
||||||
|
if nux.check.file.exists "$abs_path"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
should-not-exists.check.failed() {
|
||||||
|
for f in "$rel_path"; do
|
||||||
|
nux.dsl.error $f Should not exists, but is present.
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
.check.failed() {
|
.check.failed() {
|
||||||
nux.dsl.error "$abs_path" does not exists.
|
nux.dsl.error "$rel_path" does not exists.
|
||||||
}
|
}
|
||||||
dir.entered() {
|
dir.entered() {
|
||||||
if nux.check.file.exists "$abs_path/.nuxfs"; then
|
if nux.check.file.exists "$abs_path/.nuxfs"; then
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,8 @@ function nux.check.function {
|
||||||
function nux.check.file.exists {
|
function nux.check.file.exists {
|
||||||
test -e "$1" -o -h "$1";
|
test -e "$1" -o -h "$1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nux.eval {
|
||||||
|
nux.log trace Going to evaluate "$@"
|
||||||
|
eval "$@"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,12 @@ function nux.dsl.block.push {
|
||||||
local btype="$1"
|
local btype="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
local parent=$(nux.dsl.block.path)
|
local parent=$(nux.dsl.block.path)
|
||||||
nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack."
|
#nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack."
|
||||||
DSL_BLOCK_TYPE[${#DSL_BLOCK_TYPE[@]}]="$btype"
|
DSL_BLOCK_TYPE[${#DSL_BLOCK_TYPE[@]}]="$btype"
|
||||||
DSL_BLOCK_ID[${#DSL_BLOCK_ID[@]}]="$value"
|
DSL_BLOCK_ID[${#DSL_BLOCK_ID[@]}]="$value"
|
||||||
DSL_BLOCK_PATH[${#DSL_BLOCK_PATH[@]}]="$parent/$value";
|
DSL_BLOCK_PATH[${#DSL_BLOCK_PATH[@]}]="$parent/$value";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function nux.dsl.error {
|
function nux.dsl.error {
|
||||||
local tag="$1"; shift;
|
local tag="$1"; shift;
|
||||||
nux.echo.error "$tag"$NC_No: $*;
|
nux.echo.error "$tag"$NC_No: $*;
|
||||||
|
|
@ -41,12 +39,12 @@ function nux.dsl.error {
|
||||||
|
|
||||||
function nux.dsl.warning {
|
function nux.dsl.warning {
|
||||||
local tag="$1"; shift;
|
local tag="$1"; shift;
|
||||||
nux.echo.warning "$1"$NC_No: $*;
|
nux.echo.warning "$tag"$NC_No: $*;
|
||||||
}
|
}
|
||||||
|
|
||||||
function nux.dsl.info {
|
function nux.dsl.info {
|
||||||
local tag="$1"; shift;
|
local tag="$1"; shift;
|
||||||
echo -e $NC_White"$1"$NC_No: $*;
|
echo -e $NC_White"$tag"$NC_No: $*;
|
||||||
}
|
}
|
||||||
|
|
||||||
function nux.dsl.keyword.exec {
|
function nux.dsl.keyword.exec {
|
||||||
|
|
@ -54,15 +52,21 @@ function nux.dsl.keyword.exec {
|
||||||
local keyword="$2";
|
local keyword="$2";
|
||||||
local FUNC_NAME=$keyword$func;
|
local FUNC_NAME=$keyword$func;
|
||||||
local DEFAULT_NAME=$func;
|
local DEFAULT_NAME=$func;
|
||||||
|
local ALLWAYS_NAME=.allways$func;
|
||||||
|
|
||||||
shift; shift;
|
shift; shift;
|
||||||
|
if nux.check.function $ALLWAYS_NAME; then
|
||||||
|
nux.log trace Executing: $NC_White$ALLWAYS_NAME$NC_No "$@";
|
||||||
|
$ALLWAYS_NAME "$@";
|
||||||
|
fi
|
||||||
if nux.check.function $FUNC_NAME; then
|
if nux.check.function $FUNC_NAME; then
|
||||||
nux.log trace Executing: $NC_White$FUNC_NAME$NC_No "$@";
|
nux.log trace Executing: $NC_White$FUNC_NAME$NC_No "$@";
|
||||||
$FUNC_NAME "$@";
|
$FUNC_NAME "$@";
|
||||||
return;
|
return $?;
|
||||||
elif nux.check.function $DEFAULT_NAME; then
|
elif nux.check.function $DEFAULT_NAME; then
|
||||||
nux.log trace Executing: $NC_White$DEFAULT_NAME$NC_No "$@";
|
nux.log trace Executing: $NC_White$DEFAULT_NAME$NC_No "$@";
|
||||||
$DEFAULT_NAME "$@";
|
$DEFAULT_NAME "$@";
|
||||||
return;
|
return $?;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +81,7 @@ function nux.dsl.block.start {
|
||||||
id="$2";
|
id="$2";
|
||||||
path="$parent/$id";
|
path="$parent/$id";
|
||||||
|
|
||||||
#nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent
|
nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent
|
||||||
#nux.log debug "Skip is: $nux_dsl_skip, test should return $(test -z "$nux_dsl_skip")"
|
#nux.log debug "Skip is: $nux_dsl_skip, test should return $(test -z "$nux_dsl_skip")"
|
||||||
nux.dsl.block.push "$keyword" "$id"
|
nux.dsl.block.push "$keyword" "$id"
|
||||||
if [[ $path == $nux_dsl_only_subtree* && -z "$nux_dsl_skip" ]]; then
|
if [[ $path == $nux_dsl_only_subtree* && -z "$nux_dsl_skip" ]]; then
|
||||||
|
|
@ -102,21 +106,32 @@ function nux.dsl.block.end {
|
||||||
id=$(nux.dsl.block.id)
|
id=$(nux.dsl.block.id)
|
||||||
path=$(nux.dsl.block.path)
|
path=$(nux.dsl.block.path)
|
||||||
|
|
||||||
nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
#nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
||||||
|
nux.dsl.block.pop "$1"
|
||||||
|
|
||||||
if [ "$path" = "$nux_dsl_skip" ];then
|
if [ "$path" = "$nux_dsl_skip" ];then
|
||||||
nux_dsl_skip="";
|
nux_dsl_skip="";
|
||||||
fi
|
fi
|
||||||
nux.dsl.block.pop "$1"
|
|
||||||
if [[ $path == $nux_dsl_only_subtree* ]]; then
|
if [[ $path == $nux_dsl_only_subtree* ]]; then
|
||||||
nux.dsl.keyword.exec .exited "$keyword" "'$id'"
|
nux.dsl.keyword.exec .exited "$keyword" "'$id'"
|
||||||
|
|
||||||
nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function nux.dsl.load {
|
function nux.dsl.execute {
|
||||||
local language=$1
|
local language=$1
|
||||||
local script=$2
|
local script=$2
|
||||||
|
local language_dir=$(dirname "$language");
|
||||||
|
local script_dir=$(dirname "$script");
|
||||||
|
function .use-dsl {
|
||||||
|
if nux.check.file.exists "$language_dir/$1.dsl"; then
|
||||||
|
source "$language_dir/$1.dsl";
|
||||||
|
elif nux.check.file.exists "$script_dir/$1.dsl"; then
|
||||||
|
source "$script_dir/$1.dsl";
|
||||||
|
else
|
||||||
|
nux.dsl.error $1 Language not found in $NC_White$language_dir$NC_No and $NC_White$script_dir$NC_No
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function .entered {
|
function .entered {
|
||||||
nux.log debug Keyword $NC_White$1$NC_No is noop.
|
nux.log debug Keyword $NC_White$1$NC_No is noop.
|
||||||
|
|
@ -129,13 +144,28 @@ function nux.dsl.load {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function .arg.parser {
|
||||||
|
keyword="$1"; shift;
|
||||||
|
offset=1;
|
||||||
|
echo """# Parsing arguments
|
||||||
|
|
||||||
|
keyword=$keyword
|
||||||
|
id=\"\$1\""""
|
||||||
|
for var in "$@"; do
|
||||||
|
echo " ${var}=\"\$$offset\""
|
||||||
|
let offset=$offset+1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function .block {
|
function .block {
|
||||||
local keyword="$1"
|
local keyword="$1"
|
||||||
nux.log trace Defining block named $NCWhite"$keyword"
|
nux.log trace Defining block keyword $NC_White"$keyword"
|
||||||
#FIXME: Add aliasing of binary of same name.
|
#FIXME: Add aliasing of binary of same name.
|
||||||
eval """
|
nux.eval """
|
||||||
$keyword() {
|
$keyword() {
|
||||||
nux.dsl.block.start $keyword "\$@";
|
$(.arg.parser "$@")
|
||||||
|
nux.dsl.block.start $keyword \"\$@\";
|
||||||
}
|
}
|
||||||
end$keyword() {
|
end$keyword() {
|
||||||
nux.dsl.block.end $keyword
|
nux.dsl.block.end $keyword
|
||||||
|
|
@ -146,14 +176,37 @@ function nux.dsl.load {
|
||||||
function .keyword {
|
function .keyword {
|
||||||
local keyword="$1"
|
local keyword="$1"
|
||||||
#FIXME: Add aliasing of binary of same name.
|
#FIXME: Add aliasing of binary of same name.
|
||||||
nux.log trace Defining block named $NCWhite"$keyword"
|
nux.log trace Defining keyword $NC_White"$keyword"
|
||||||
eval """
|
nux.eval """
|
||||||
$keyword() {
|
$keyword() {
|
||||||
nux.dsl.block.start $keyword "\$@";
|
$(.arg.parser "$@")
|
||||||
|
nux.dsl.block.start $keyword \"\$@\";
|
||||||
nux.dsl.block.end $keyword;
|
nux.dsl.block.end $keyword;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keyword.virtual() {
|
||||||
|
local keyword=$1
|
||||||
|
.keyword "$@"
|
||||||
|
nux.eval """
|
||||||
|
${keyword}.check() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
.block.virtual() {
|
||||||
|
local keyword=$1
|
||||||
|
.block "$@"
|
||||||
|
nux.eval """
|
||||||
|
${keyword}.check() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
nux.dsl.block.init
|
nux.dsl.block.init
|
||||||
$language
|
source "$language.dsl"
|
||||||
|
source "$script"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue