Update build of bin/dotify

This commit is contained in:
2014-08-21 03:03:02 +01:00
parent 264e362872
commit 2560964db6

View File

@@ -254,7 +254,7 @@ dotify-setup-root-link() {
# #
dotify-set-default-action() { dotify-set-default-action() {
DOTIFY_ATTR_DEFAULT_ACTION="$1" DOTIFY_ATTR_DEFAULT_ACTION="$@"
} }
dotify-get-default-action() { dotify-get-default-action() {
@@ -271,11 +271,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
@@ -295,14 +295,14 @@ dotify-valid-dotfile-path() {
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"
} }
dotify-set-root-link() { dotify-set-root-link() {
DOTIFY_ATTR_ROOT_LINK="$1" DOTIFY_ATTR_ROOT_LINK="$@"
} }
dotify-get-root-link() { dotify-get-root-link() {
@@ -339,11 +339,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
@@ -500,11 +500,11 @@ dotify-action-git-post-run() {
# #
root_link () { root_link () {
dotify-set-root-link "$@" dotify-set-root-link $@
} }
default_action() { default_action() {
dotify-set-default-action "$@" dotify-set-default-action $@
} }
include() { include() {
@@ -513,81 +513,97 @@ include() {
# #
# Argument Parsing # Main
# #
ARG_DOTFILE="" # --dotfile / -f dotify-main-parse-arguments() {
ARG_TARGET="" # --target / -t DOTIFY_ARG_DOTFILE="" # --dotfile / -f
ARG_DRY_RUN="" # --dry-run / -d DOTIFY_ARG_TARGET="" # --target / -t
ARG_HELP="" # --help / -h DOTIFY_ARG_DRY_RUN="" # --dry-run / -d
ARG_VERSION="" # --version / -v DOTIFY_ARG_HELP="" # --help / -h
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
if has-argument target t "$@"; then
ARG_TARGET="$(parse-argument target t "$@")"
fi
if has-argument dry-run d "$@"; then
ARG_DRY_RUN="1"
fi
if has-argument help h "$@"; then
ARG_HELP="1"
fi
if has-argument version v "$@"; then
ARG_VERSION="1"
fi
#
# Command Parsing
#
# Command is first argument that does not start with a dash or plus.
for arg in "$@"; do
if [ -n "$skip_next" ]; then
skip_next=
elif [[ "$arg" =~ ^(--dotfile|-f|--taraget|-t)$ ]]; then
skip_next=1
elif [[ "$arg" != "-"* ]] && [[ "$arg" != "+"* ]]; then
command="$arg"
break
fi fi
done
# Show help and exit if help arguments or command are given. if has-argument target t "$@"; then
if [ -n "$ARG_HELP" ] || [ "$command" == "help" ]; then DOTIFY_ARG_TARGET="$(parse-argument target t "$@")"
dotify-command-help fi
exit
fi
# Show version info and exit if version arguments or command are given. if has-argument dry-run d "$@"; then
if [ -n "$ARG_VERSION" ] || [ "$command" == "version" ]; then DOTIFY_ARG_DRY_RUN="1"
dotify-command-help | head -1 fi
exit
fi
# Deal with the commands. if has-argument help h "$@"; then
case "$command" in DOTIFY_ARG_HELP="1"
"info" ) fi
dotify-command-info
;; if has-argument version v "$@"; then
"compile" ) DOTIFY_ARG_VERSION="1"
dotify-command-compile fi
;; }
"" | "install" )
dotify-command-install dotify-main-parse-command() {
;; local skip_next
"uninstall" )
dotify-command-uninstall # Command is first argument that does not start with a dash or plus.
;; for arg in "$@"; do
"clean" ) if [ -n "$skip_next" ]; then
dotify-command-clean skip_next=
;; elif [[ "$arg" =~ ^(--dotfile|-f|--taraget|-t)$ ]]; then
esac skip_next=1
elif [[ "$arg" != "-"* ]] && [[ "$arg" != "+"* ]]; then
DOTIFY_COMMAND="$arg"
break
fi
done
}
dotify-main-dispatcher() {
# Show help and exit if help arguments or command are given.
if [ -n "$DOTIFY_ARG_HELP" ] || [ "$DOTIFY_COMMAND" == "help" ]; then
dotify-command-help
exit
fi
# Show version info and exit if version arguments or command are given.
if [ -n "$DOTIFY_ARG_VERSION" ] || [ "$DOTIFY_COMMAND" == "version" ]; then
dotify-command-help | head -1
exit
fi
# Deal with the commands.
case "$DOTIFY_COMMAND" in
"info" )
dotify-command-info
;;
"compile" )
dotify-command-compile
;;
"" | "install" )
dotify-command-install
;;
"uninstall" )
dotify-command-uninstall
;;
"clean" )
dotify-command-clean
;;
esac
return $?
}
dotify-main() {
dotify-main-parse-arguments $@
dotify-main-parse-command $@
dotify-main-dispatcher $@
return $?
}
dotify-main $@
exit $? exit $?