diff --git a/src/lib/dotify-action.sh b/src/lib/dotify-action.sh index eb5268c..bb65a86 100644 --- a/src/lib/dotify-action.sh +++ b/src/lib/dotify-action.sh @@ -1,17 +1,26 @@ dotify-action() { local action="$1" - local source="$2" - local target="$3" + + if [ $# -lt 3 ]; then + local target="$2" + else + local source="$2" + local target="$3" + fi if [ "$action" == "default" ]; then action="$DOTIFY_OPT_DEFAULT_ACTION" fi - ! valid_action="$(command -v "dotify-action-${action}")" + ! local valid_action="$(command -v "dotify-action-${action}")" if [ -z "$valid_action" ]; then echo "ERROR: \"$action\" is not a valid action." >&2 return 1 fi - dotify-action-${action} "$source" "$target" + if [ -n "$source" ]; then + dotify-action-${action} "$DOTIFY_RUN_MODE" "$target" "$source" + else + dotify-action-${action} "$DOTIFY_RUN_MODE" "$target" + fi } diff --git a/test/lib/dotify-action-test.sh b/test/lib/dotify-action-test.sh index 85b7f20..89d716a 100755 --- a/test/lib/dotify-action-test.sh +++ b/test/lib/dotify-action-test.sh @@ -6,7 +6,8 @@ source "../../src/lib/dotify-action.sh" # dotify-action() tests # -# Set required option ENV +# Set required environment variables. +DOTIFY_RUN_MODE="install" DOTIFY_OPT_DEFAULT_ACTION="link" # Simple mock for link action. @@ -16,10 +17,17 @@ dotify-action-link() { # Given a specific action. -assert "dotify-action link ackrc .ackrc" "link stub: ackrc .ackrc" +assert "dotify-action link ackrc .ackrc" "link stub: install .ackrc ackrc" + +# Given a specific action without a . +assert "dotify-action link .ackrc" "link stub: install .ackrc" # Given "default" action, it uses configured default action. -assert "dotify-action default ackrc .ackrc" "link stub: ackrc .ackrc" +assert "dotify-action default ackrc .ackrc" "link stub: install .ackrc ackrc" + +# Given "default" action without a , it uses configured default +# action. +assert "dotify-action default .ackrc" "link stub: install .ackrc" # Given a invalid action. assert_raises "dotify-action foo ackrc .ackrc" 1