Blame Functions/Path/path_getActions.sh

407d66
#!/bin/bash
407d66
#
8ba5a0
# path_getActions.sh -- This function interpretes arguments passed to
8ba5a0
# `path' functionality and calls actions accordingly.
407d66
#
ff008e
# Copyright (C) 2009-2011 Alain Reguera Delgado
407d66
# 
72c8a5
# This program is free software; you can redistribute it and/or
72c8a5
# modify it under the terms of the GNU General Public License as
72c8a5
# published by the Free Software Foundation; either version 2 of the
72c8a5
# License, or (at your option) any later version.
407d66
# 
407d66
# This program is distributed in the hope that it will be useful, but
407d66
# WITHOUT ANY WARRANTY; without even the implied warranty of
407d66
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
407d66
# General Public License for more details.
407d66
#
407d66
# You should have received a copy of the GNU General Public License
407d66
# along with this program; if not, write to the Free Software
407d66
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
407d66
# USA.
407d66
# 
407d66
# ----------------------------------------------------------------------
407d66
# $Id$
407d66
# ----------------------------------------------------------------------
407d66
    
407d66
function path_getActions {
407d66
6ecc07
    # Define short options we want to support.
8ba5a0
    local ARGSS=""
6ecc07
6ecc07
    # Define long options we want to support.
d47704
    local ARGSL="copy:,move:,delete:,to:,sync"
6ecc07
6ecc07
    # Parse arguments using getopt(1) command parser.
6ecc07
    cli_doParseArguments
6ecc07
6ecc07
    # Reset positional parameters using output from (getopt) argument
6ecc07
    # parser.
6ecc07
    eval set -- "$ARGUMENTS"
6ecc07
8ba5a0
    # Define action to take for each option passed.
6ecc07
    while true; do
6ecc07
        case "$1" in
6ecc07
8ba5a0
            --copy )
6ecc07
8ba5a0
                # Define action value passed through the command-line.
8ba5a0
                ACTIONVAL="$2"
6ecc07
8ba5a0
                # Define action name using action value as reference.
8ba5a0
                ACTIONNAM="${FUNCNAM}_doCopy"
407d66
ff008e
                # Rotate positional parameters.
ff008e
                shift 2
407d66
                ;;
8ba5a0
ff008e
            --delete )
8ba5a0
8ba5a0
                # Define action value passed through the command-line.
8ba5a0
                ACTIONVAL="$2"
8ba5a0
8ba5a0
                # Define action name using action value as reference.
ff008e
                ACTIONNAM="${FUNCNAM}_doDelete"
8ba5a0
ff008e
                # Rotate positional parameters.
ff008e
                shift 2
ff008e
                ;;
8ba5a0
ff008e
            --to )
8ba5a0
ff008e
                # Redefine target flag.
ff008e
                FLAG_TO="$2"
8ba5a0
ff008e
                # Verify target directory.
ff008e
                cli_checkRepoDirTarget
8ba5a0
ff008e
                # Rotate positional parameters.
ff008e
                shift 2
ff008e
                ;;
8ba5a0
ff008e
            --sync )
8ba5a0
ff008e
                # Redefine syncronization flag.
ff008e
                FLAG_SYNC='true'
ff008e
ff008e
                # Rotate positional parameters.
ff008e
                shift 1
407d66
                ;;
407d66
8ba5a0
            * )
8ba5a0
                # Break options loop.
8ba5a0
                break
407d66
        esac
407d66
    done
8ba5a0
ff008e
    # Check action value (ACTIONVAL) passed through the command-line
ff008e
    # using source directory definition as reference.
ff008e
    cli_checkRepoDirSource
ff008e
d47704
    # Syncronize changes between the working copy and the central
d47704
    # repository to bring down changes.
f54510
    cli_syncroRepoChanges "${ACTIOVAL} ${FLAG_TO}"
d47704
8ba5a0
    # Execute action name.
8ba5a0
    if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then
8ba5a0
        eval $ACTIONNAM
8ba5a0
    else
8ba5a0
        cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine'
8ba5a0
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
8ba5a0
    fi
8ba5a0
d47704
    # Syncronize changes between the working copy and the central
d47704
    # repository to commit up changes.
d47704
    cli_commitRepoChanges "${ACTIOVAL} ${FLAG_TO}"
d47704
407d66
}