1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

nuxfs: added init and templates support.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2016-11-24 13:34:01 +01:00
parent 1737416a72
commit e4ae60fdb0
2 changed files with 65 additions and 6 deletions

View file

@ -2,7 +2,10 @@
### Filesystem Layout manager
###
STARTDIR=$(pwd)
local STARTDIR=$(pwd)
local TEMPLATE_DIR=$NUX_ENV_DIR/templates
local SUFFIX=".nuxfs"
local TEMPLATE_FILTER="*$SUFFIX"
nux.include nuxfs
nux.include nuxfs.dsl
@ -65,5 +68,57 @@ function task.create {
popd > /dev/null;
}
nuxfs.dsl.execute .nuxfs
nuxfs.dsl.execute $SUFFIX
}
## init - Initializes a directory using template
function task.init {
if [ $# -eq 0 ]; then
nux.log debug "No template specified. Creating empty $SUFFIX definition."
touch .nuxfs
return;
fi
local TEMPLATE=$1
nux.log debug "User specified template is " $TEMPLATE
if [ $(echo $TEMPLATE | grep -c "$SUFFIX\$") -eq 0 ]; then
nux.log debug "Template is common template."
TEMPLATE=$TEMPLATE_DIR/$TEMPLATE$SUFFIX
if [ ! -e $TEMPLATE ]; then
echo -n "Template '$1' does not exists. "
nuxfs.template.list
return;
fi;
fi;
nux.log debug "Using '$TEMPLATE' to initialize."
if [ ! -e $TEMPLATE ]; then
echo "nuxfs template $1 does not exists."
return;
fi;
local template_relative=$(realpath -Lms $TEMPLATE --relative-to $(pwd))
nux.log debug "Creating link $SUFFIX: target is '$template_relative'";
ln -s "$template_relative" "$SUFFIX"
nux.log debug "Invoking create task."
task.create
}
##
## template - List available templates
#
function task.template {
nux.log debug $NUX_ENV_DIR
nuxfs.template.list
}
function nuxfs.template.list {
echo "Available templates:";
pushd $TEMPLATE_DIR > /dev/null;
for i in $TEMPLATE_FILTER; do
local TEMPLATE_ID=$(basename $i $SUFFIX)
echo -n " $TEMPLATE_ID - " ;
grep -m1 "^name " $i | sed -e "s/name *//"
echo
done;
popd > /dev/null;
}

View file

@ -6,12 +6,12 @@ function exec.if.function {
shift; shift;
if nux.check.function $FUNC_NAME; then
nux.log debug Executing: $FUNC_NAME "$@";
nux.log trace Executing: $FUNC_NAME "$@";
$FUNC_NAME "$@";
return;
fi
if nux.check.function $DEFAULT_NAME; then
nux.log debug Executing: $FUNC_NAME "$@";
nux.log trace Executing: $FUNC_NAME "$@";
$DEFAULT_NAME "$@";
return;
fi
@ -43,6 +43,9 @@ function nuxfs.dsl.keywords {
origin() {
:
}
name() {
:
}
dir() {
nuxfs.dsl.command directory "$@";
}
@ -71,6 +74,7 @@ function nuxfs.dsl.keywords {
nux.log debug "Directory exists '$1'"
nux.log trace "Trying to nest into directory"
if test -e "$1/.nuxfs"; then
nux.log debug "Invoking nested nuxfs definition."
source "$1/.nuxfs";
fi;
else
@ -89,9 +93,9 @@ function nuxfs.dsl.execute {
nuxfs.dsl.keywords
declare -a DIR_ARRAY
DIR_ARRAY[0]=.
if test -f "$1"; then
if test -e "$1"; then
source $1;
else
error "$1": Definition file does not exists.
nuxfs.error "$1" Definition file does not exists.
fi
}