Blame Scripts/Bash/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
#
72c8a5
# 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.
8ba5a0
    local ARGSL="copy:,move:,delete:,to:"
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
                # Check action value passed through the command-line
8ba5a0
                # using source directory definition as reference.
8ba5a0
                cli_checkRepoDirSource
407d66
8ba5a0
                # Define action name using action value as reference.
8ba5a0
                ACTIONNAM="${FUNCNAM}_doCopy"
407d66
8ba5a0
                # Look for related sub-options.
8ba5a0
                while true; do
8ba5a0
                    case "$3" in
407d66
8ba5a0
                        --to )
8ba5a0
8ba5a0
                            # Redefine target directory.
8ba5a0
                            TARGET="$4"
8ba5a0
8ba5a0
                            # Verify target directory.
8ba5a0
                            cli_checkRepoDirTarget
8ba5a0
8ba5a0
                            # Rotate positional parameters.
8ba5a0
                            shift 4
8ba5a0
                            ;;
8ba5a0
8ba5a0
                        * )
8ba5a0
                            # Break sub-options loop.
8ba5a0
                            break
8ba5a0
                            ;;
8ba5a0
                    esac
8ba5a0
                done
8ba5a0
8ba5a0
                # Break options loop.
8ba5a0
                break
407d66
                ;;
8ba5a0
8ba5a0
            --move )
8ba5a0
8ba5a0
                # Define action value passed through the command-line.
8ba5a0
                ACTIONVAL="$2"
8ba5a0
8ba5a0
                # Check action value passed through the command-line
8ba5a0
                # using source directory definition as reference.
8ba5a0
                cli_checkRepoDirSource
8ba5a0
8ba5a0
                # Define action name using action value as reference.
8ba5a0
                ACTIONNAM="${FUNCNAM}_doMove"
8ba5a0
8ba5a0
                # Look for related sub-options.
8ba5a0
                while true; do
8ba5a0
                    case "$3" in
8ba5a0
8ba5a0
                        --to )
8ba5a0
8ba5a0
                            # Redefine target directory.
8ba5a0
                            TARGET="$4"
8ba5a0
8ba5a0
                            # Verify target directory.
8ba5a0
                            cli_checkRepoDirTarget
8ba5a0
8ba5a0
                            # Rotate positional parameters.
8ba5a0
                            shift 4
8ba5a0
                            ;;
8ba5a0
8ba5a0
                        * )
8ba5a0
                            # Break sub-options loop.
8ba5a0
                            break
8ba5a0
                            ;;
8ba5a0
                    esac
8ba5a0
                done
8ba5a0
8ba5a0
                # Break options loop.
8ba5a0
                break
407d66
                ;;
407d66
8ba5a0
            --delete )
8ba5a0
8ba5a0
                # Define action value passed through the command-line.
8ba5a0
                ACTIONVAL="$2"
8ba5a0
8ba5a0
                # Check action value passed through the command-line
8ba5a0
                # using source directory definition as reference.
8ba5a0
                cli_checkRepoDirSource
8ba5a0
8ba5a0
                # Define action name using action value as reference.
8ba5a0
                ACTIONNAM="${FUNCNAM}_doDelete"
8ba5a0
8ba5a0
                # Break options loop.
8ba5a0
                break
407d66
                ;;
407d66
8ba5a0
            * )
8ba5a0
                # Break options loop.
8ba5a0
                break
407d66
        esac
407d66
    done
8ba5a0
8ba5a0
    # Verify action value variable.
8ba5a0
    if [[ $ACTIONVAL == '' ]];then
8ba5a0
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
8ba5a0
    fi
8ba5a0
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
407d66
}