Change how plugins/actions work a bit

This includes both how they detect what the current
mode (install/uninstall/cleanup/etc) is, and also forces them to
register themselves with Dotify. The registration will be used for
running pre/post hooks.
This commit is contained in:
2014-03-08 13:26:42 +00:00
parent 3e6f1b02c3
commit 8fa09ea3c3
6 changed files with 73 additions and 34 deletions

32
src/actions/git.sh Normal file
View File

@@ -0,0 +1,32 @@
# Register git action
dotify-register-action "git"
# Git action.
dotify-action-git() {
local mode="$1"
! local valid_mode="$(command -v "dotify-action-git-do-${mode}")"
if [ -n "$valid_mode" ]; then
shift 1
dotify-action-git-do-${mode} $@
fi
}
dotify-action-git-do-install() {
echo "git install: $@"
}
dotify-action-git-do-uninstall() {
echo "git uninstall: $@"
}
dotify-action-git-do-cleanup() {
echo "git cleanup: $@"
}
dotify-action-git-post-run() {
if [ "$1" == "cleanup" ]; then
shift 1
dotify-action-link-do-cleanup $@
fi
}

32
src/actions/link.sh Normal file
View File

@@ -0,0 +1,32 @@
# Register link action.
dotify-register-action "link"
# Link action.
dotify-action-link() {
local mode="$1"
! local valid_mode="$(command -v "dotify-action-link-do-${mode}")"
if [ -n "$valid_mode" ]; then
shift 1
dotify-action-link-do-${mode} $@
fi
}
dotify-action-link-do-install() {
echo "link install: $@"
}
dotify-action-link-do-uninstall() {
echo "link uninstall: $@"
}
dotify-action-link-do-cleanup() {
echo "link cleanup: $@"
}
dotify-action-link-post-run() {
if [ "$1" == "cleanup" ]; then
shift 1
dotify-action-link-do-cleanup $@
fi
}

View File

@@ -45,7 +45,7 @@ source "../lib/internals/locate-dotfile.sh"
source "../lib/internals/locate-target.sh"
#
# Command functions
# Main functions
#
source "../lib/dotify-action.sh"
@@ -54,15 +54,16 @@ source "../lib/dotify-compile.sh"
source "../lib/dotify-help.sh"
source "../lib/dotify-info.sh"
source "../lib/dotify-install.sh"
source "../lib/dotify-register-action.sh"
source "../lib/dotify-uninstall.sh"
source "../lib/dotify-version.sh"
#
# Built-in Plugins
# Built-in action plugins
#
source "../plugins/link.sh"
source "../plugins/git.sh"
source "../actions/link.sh"
source "../actions/git.sh"
#
# Dotfile commands

View File

@@ -0,0 +1,4 @@
dotify-register-action() {
if [ -z "$DOTIFY_ACTIONS" ]; then DOTIFY_ACTIONS=(); fi
DOTIFY_ACTIONS+=("$1")
}

View File

@@ -1,15 +0,0 @@
dotify-action-git() {
if [ "$DOTIFY_RUN_MODE" == "install" ]; then
dotify-action-git-install $@
elif [ "$DOTIFY_RUN_MODE" == "uninstall" ]; then
dotify-action-git-uninstall $@
fi
}
dotify-action-git-install() {
echo "git install: $@"
}
dotify-action-git-uninstall() {
echo "git uninstall: $@"
}

View File

@@ -1,15 +0,0 @@
dotify-action-link() {
if [ "$DOTIFY_RUN_MODE" == "install" ]; then
dotify-action-link-install $@
elif [ "$DOTIFY_RUN_MODE" == "uninstall" ]; then
dotify-action-link-uninstall $@
fi
}
dotify-action-link-install() {
echo "link install: $@"
}
dotify-action-link-uninstall() {
echo "link uninstall: $@"
}