Namespace global variables

This commit is contained in:
2014-08-21 03:02:35 +01:00
parent 6bddccd199
commit 264e362872
6 changed files with 23 additions and 23 deletions

View File

@@ -4,11 +4,11 @@ dotify-get-dotfile-path() {
return 0 return 0
fi fi
if [ -n "$ARG_DOTFILE" ]; then if [ -n "$DOTIFY_ARG_DOTFILE" ]; then
if [ -f "$ARG_DOTFILE" ]; then if [ -f "$DOTIFY_ARG_DOTFILE" ]; then
DOTIFY_ATTR_DOTFILE_PATH="$ARG_DOTFILE" DOTIFY_ATTR_DOTFILE_PATH="$DOTIFY_ARG_DOTFILE"
else else
echo "ERROR: \"$ARG_DOTFILE\" does not exist." >&2 echo "ERROR: \"$DOTIFY_ARG_DOTFILE\" does not exist." >&2
return 1 return 1
fi fi
elif [ -f "$(pwd)/Dotfile" ]; then elif [ -f "$(pwd)/Dotfile" ]; then

View File

@@ -1,6 +1,6 @@
dotify-get-dry-run() { dotify-get-dry-run() {
if [ -n "$DOTIFY_ATTR_DRY_RUN" ]; then if [ -n "$DOTIFY_ATTR_DRY_RUN" ]; then
DOTIFY_ATTR_DRY_RUN="$ARG_DRY_RUN" DOTIFY_ATTR_DRY_RUN="$DOTIFY_ARG_DRY_RUN"
fi fi
echo "$DOTIFY_ATTR_DRY_RUN" echo "$DOTIFY_ATTR_DRY_RUN"

View File

@@ -4,11 +4,11 @@ dotify-get-target-path() {
return 0 return 0
fi fi
if [ -n "$ARG_TARGET" ]; then if [ -n "$DOTIFY_ARG_TARGET" ]; then
if [ -d "$ARG_TARGET" ]; then if [ -d "$DOTIFY_ARG_TARGET" ]; then
DOTIFY_ATTR_TARGET="$ARG_TARGET" DOTIFY_ATTR_TARGET="$DOTIFY_ARG_TARGET"
else else
echo "ERROR: Target \"$ARG_TARGET\" is not a directory." >&2 echo "ERROR: Target \"$DOTIFY_ARG_TARGET\" is not a directory." >&2
return 1 return 1
fi fi
elif [ -n "$HOME" ] && [ -d "$HOME" ]; then elif [ -n "$HOME" ] && [ -d "$HOME" ]; then

View File

@@ -1,18 +1,18 @@
dotify-main-dispatcher() { dotify-main-dispatcher() {
# Show help and exit if help arguments or command are given. # Show help and exit if help arguments or command are given.
if [ -n "$ARG_HELP" ] || [ "$COMMAND" == "help" ]; then if [ -n "$DOTIFY_ARG_HELP" ] || [ "$DOTIFY_COMMAND" == "help" ]; then
dotify-command-help dotify-command-help
exit exit
fi fi
# Show version info and exit if version arguments or command are given. # Show version info and exit if version arguments or command are given.
if [ -n "$ARG_VERSION" ] || [ "$COMMAND" == "version" ]; then if [ -n "$DOTIFY_ARG_VERSION" ] || [ "$DOTIFY_COMMAND" == "version" ]; then
dotify-command-help | head -1 dotify-command-help | head -1
exit exit
fi fi
# Deal with the commands. # Deal with the commands.
case "$COMMAND" in case "$DOTIFY_COMMAND" in
"info" ) "info" )
dotify-command-info dotify-command-info
;; ;;

View File

@@ -1,27 +1,27 @@
dotify-main-parse-arguments() { dotify-main-parse-arguments() {
ARG_DOTFILE="" # --dotfile / -f DOTIFY_ARG_DOTFILE="" # --dotfile / -f
ARG_TARGET="" # --target / -t DOTIFY_ARG_TARGET="" # --target / -t
ARG_DRY_RUN="" # --dry-run / -d DOTIFY_ARG_DRY_RUN="" # --dry-run / -d
ARG_HELP="" # --help / -h DOTIFY_ARG_HELP="" # --help / -h
ARG_VERSION="" # --version / -v DOTIFY_ARG_VERSION="" # --version / -v
if has-argument dotfile f "$@"; then if has-argument dotfile f "$@"; then
ARG_DOTFILE="$(parse-argument dotfile f "$@")" DOTIFY_ARG_DOTFILE="$(parse-argument dotfile f "$@")"
fi fi
if has-argument target t "$@"; then if has-argument target t "$@"; then
ARG_TARGET="$(parse-argument target t "$@")" DOTIFY_ARG_TARGET="$(parse-argument target t "$@")"
fi fi
if has-argument dry-run d "$@"; then if has-argument dry-run d "$@"; then
ARG_DRY_RUN="1" DOTIFY_ARG_DRY_RUN="1"
fi fi
if has-argument help h "$@"; then if has-argument help h "$@"; then
ARG_HELP="1" DOTIFY_ARG_HELP="1"
fi fi
if has-argument version v "$@"; then if has-argument version v "$@"; then
ARG_VERSION="1" DOTIFY_ARG_VERSION="1"
fi fi
} }

View File

@@ -8,7 +8,7 @@ dotify-main-parse-command() {
elif [[ "$arg" =~ ^(--dotfile|-f|--taraget|-t)$ ]]; then elif [[ "$arg" =~ ^(--dotfile|-f|--taraget|-t)$ ]]; then
skip_next=1 skip_next=1
elif [[ "$arg" != "-"* ]] && [[ "$arg" != "+"* ]]; then elif [[ "$arg" != "-"* ]] && [[ "$arg" != "+"* ]]; then
COMMAND="$arg" DOTIFY_COMMAND="$arg"
break break
fi fi
done done