Blame Automation/centos-art.sh-mods/Commons/cli_parseArgumentsReDef.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# cli_parseArgumentsReDef.sh -- This function initiates/reset and
Alain Reguera Delgado 8f60cb
# sanitizes positional parameters passed to this function and creates
Alain Reguera Delgado 8f60cb
# the list of arguments that getopt will process.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function cli_parseArgumentsReDef {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local ARG
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Clean up arguments global variable.
Alain Reguera Delgado 8f60cb
    ARGUMENTS=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Fill up arguments global variable with current positional
Alain Reguera Delgado 8f60cb
    # parameter  information. To avoid interpretation problems, use
Alain Reguera Delgado 8f60cb
    # single quotes to enclose each argument (ARG) from command-line
Alain Reguera Delgado 8f60cb
    # individually.
Alain Reguera Delgado 8f60cb
    for ARG in "$@"; do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Remove any single quote from arguments passed to
Alain Reguera Delgado 8f60cb
        # centos-art.sh script. We will use single quotes for grouping
Alain Reguera Delgado 8f60cb
        # option values so white space can be passed through them.
Alain Reguera Delgado 8f60cb
        ARG=$(echo "$ARG" | tr -d "'")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Concatenate arguments and enclose them to let getopt to
Alain Reguera Delgado 8f60cb
        # process them when they have spaces inside.
Alain Reguera Delgado 8f60cb
        ARGUMENTS="$ARGUMENTS '$ARG'"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify non-option arguments passed to command-line. If there
Alain Reguera Delgado 8f60cb
    # isn't any or dot is provided, redefine the ARGUMENTS variable to
Alain Reguera Delgado 8f60cb
    # use the current location the centos-art.sh script was called
Alain Reguera Delgado 8f60cb
    # from.
Alain Reguera Delgado 8f60cb
    if [[ -z $ARGUMENTS ]];then 
Alain Reguera Delgado 8f60cb
        ARGUMENTS=${PWD}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}