Blame Scripts/Bash/Functions/cli_getActionArguments.sh

b7b189
#!/bin/bash
b7b189
#
b7b189
# cli_getActionArguments.sh -- This function initializes the action
b7b189
# name and value used by functionalities to perform their goals.
b7b189
#
b7b189
# Copyright (C) 2009, 2010 Alain Reguera Delgado
b7b189
# 
b7b189
# This program is free software; you can redistribute it and/or modify
b7b189
# it under the terms of the GNU General Public License as published by
b7b189
# the Free Software Foundation; either version 2 of the License, or
b7b189
# (at your option) any later version.
b7b189
# 
b7b189
# This program is distributed in the hope that it will be useful, but
b7b189
# WITHOUT ANY WARRANTY; without even the implied warranty of
b7b189
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b7b189
# General Public License for more details.
b7b189
#
b7b189
# You should have received a copy of the GNU General Public License
b7b189
# along with this program; if not, write to the Free Software
b7b189
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
b7b189
# USA.
b7b189
# 
b7b189
# ----------------------------------------------------------------------
b7b189
# $Id$
b7b189
# ----------------------------------------------------------------------
b7b189
b7b189
function cli_getActionArguments {
b7b189
b7b189
    # Set command-line arguments for processing using positional
b7b189
    # parameters variables.
b7b189
    eval set -- "$ARGUMENTS"
b7b189
b7b189
    # Define function name (FUNCNAM) variable from first command-line
b7b189
    # argument.  As convenction we use the first argument to determine
b7b189
    # the exact name of functionality to call. Later we use action
b7b189
    # name (ACTIONNAM) and action value (ACTIONVAL) to know, inside
b7b189
    # functionality defined by FUNCNAME, the exact action to perform.
b7b189
    FUNCNAM=$(cli_getRepoName "$1" 'f')
b7b189
b7b189
    # Define action name (ACTIONNAM) and action value (ACTIONVAL)
b7b189
    # variables passed as second argument to the command line
b7b189
    # interface when the format is `--option=value' without the value
b7b189
    # # part.
b7b189
    if [[ "$2" =~ '^--[a-z-]+=.+$' ]];then
b7b189
b7b189
        # Define action name passed in the second argument.
b7b189
        ACTIONNAM=$(echo "$2" | cut -d = -f1)
b7b189
b7b189
        # Define action value passed in the second argument. 
b7b189
        ACTIONVAL=$(echo "$2" | cut -d = -f2-)
b7b189
b7b189
    # Define action name (ACTIONNAM), and action value (ACTIONVAL)
b7b189
    # variables passed as second argument to the command line
b7b189
    # interface when the format is `--option' without the value part.
b7b189
    elif [[ "$2" =~ '^--[a-z-]+=?$' ]];then
b7b189
b7b189
        # Define action name passed in the second argument.
b7b189
        ACTIONNAM=$(echo "$2" | cut -d = -f1)
b7b189
b7b189
        # Define action value passed in the second argument.  There is
b7b189
        # no action value (ACTIONVAL) entered from command-line here.
b7b189
        # To find out which action value to use, check current working
b7b189
        # directory, and if inside the repository, use current working
b7b189
        # directory as ACTIONVAL default value.
b7b189
        if [[ $(pwd) =~ '^/home/centos/artwork' ]];then
b7b189
            ACTIONVAL=$(pwd)
b7b189
        fi
b7b189
b7b189
    # Define default action when second argument is wrongly specified,
b7b189
    # or not specified at all.
b7b189
    else
b7b189
        cli_printMessage "`gettext "Missing arguments."`" 'AsErrorLine'
b7b189
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
b7b189
    fi
b7b189
b7b189
    # Check action value passed in the second argument.
b7b189
    cli_checkActionArguments
b7b189
b7b189
    # Remove the first and second arguments passed to centos-art.sh
b7b189
    # command-line in order to build optional arguments, they are
b7b189
    # already set in FUNCNAM, ACTIONNAM, and ACTIONVAL variables, so
b7b189
    # we remove it from command-line arguments in order for getopt to
b7b189
    # interpret it not.  Now, what was preivously set on $2 is now at
b7b189
    # $1, what was previously set on $3 is now set at $2, and so on.
b7b189
    shift 2
b7b189
b7b189
    # Redefine positional parameters stored inside ARGUMENTS variable.
b7b189
    cli_doParseArgumentsReDef "$@"
b7b189
b7b189
}