|
Alain Reguera Delgado |
615395 |
#!/bin/bash
|
|
Alain Reguera Delgado |
615395 |
######################################################################
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# cli_setArguments.sh -- This function uses getopt to process
|
|
Alain Reguera Delgado |
615395 |
# arguments passed to centos-art.sh script.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# This function works with the following three variables:
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# ARGSS
|
|
Alain Reguera Delgado |
615395 |
# Stores getopt short arguments definition.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# ARGSL
|
|
Alain Reguera Delgado |
615395 |
# Stores getopt long arguments definition.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
0de111 |
# TCAR_MODULE_ARGUMENTS
|
|
Alain Reguera Delgado |
615395 |
# Stores arguments passed to functions or command-line
|
|
Alain Reguera Delgado |
615395 |
# interface depending the context it is defined.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# These three variables are not defined in this function but the
|
|
Alain Reguera Delgado |
615395 |
# function environment you want to provide option parsing for,
|
|
Alain Reguera Delgado |
615395 |
# through getopt command. Using local definition for these three
|
|
Alain Reguera Delgado |
615395 |
# variables let you to nest option parsing inside different
|
|
Alain Reguera Delgado |
615395 |
# function-environment levels.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# Written by:
|
|
Alain Reguera Delgado |
615395 |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
615395 |
# Key fingerprint = D67D 0F82 4CBD 90BC 6421 DF28 7CCE 757C 17CA 3951
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# Copyright (C) 2009-2013 The CentOS Project
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
615395 |
# it under the terms of the GNU General Public License as published by
|
|
Alain Reguera Delgado |
615395 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
Alain Reguera Delgado |
615395 |
# your option) any later version.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# This program is distributed in the hope that it will be useful, but
|
|
Alain Reguera Delgado |
615395 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
615395 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
615395 |
# General Public License for more details.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
615395 |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
615395 |
######################################################################
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
function cli_setArguments {
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Verify existence of arguments that will be processed. If there
|
|
Alain Reguera Delgado |
615395 |
# is none, return to caller.
|
|
Alain Reguera Delgado |
615395 |
if [[ -z "${@}" ]];then
|
|
Alain Reguera Delgado |
615395 |
return
|
|
Alain Reguera Delgado |
615395 |
fi
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
local ARGUMENT=''
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Fill up arguments global variable with current positional
|
|
Alain Reguera Delgado |
615395 |
# parameter information. To avoid interpretation problems, use
|
|
Alain Reguera Delgado |
0de111 |
# single quotes to enclose each argument (TCAR_MODULE_ARGUMENTS) from
|
|
Alain Reguera Delgado |
615395 |
# command-line individually.
|
|
Alain Reguera Delgado |
615395 |
for ARGUMENT in "${@}"; do
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Remove any single quote from arguments passed to
|
|
Alain Reguera Delgado |
615395 |
# centos-art.sh script. We will use single quotes for grouping
|
|
Alain Reguera Delgado |
615395 |
# option values so white space can be passed through them.
|
|
Alain Reguera Delgado |
615395 |
ARGUMENT=$(echo "${ARGUMENT}" | tr -d "'")
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Concatenate arguments and enclose them to let getopt to
|
|
Alain Reguera Delgado |
615395 |
# process them when they have spaces inside.
|
|
Alain Reguera Delgado |
0de111 |
TCAR_MODULE_ARGUMENTS="${TCAR_MODULE_ARGUMENTS} '${ARGUMENT}'"
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
done
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Verify non-option arguments passed to command-line. If there
|
|
Alain Reguera Delgado |
0de111 |
# isn't any or dot is provided, redefine the TCAR_MODULE_ARGUMENTS variable to
|
|
Alain Reguera Delgado |
615395 |
# use the current location the centos-art.sh script was called
|
|
Alain Reguera Delgado |
615395 |
# from.
|
|
Alain Reguera Delgado |
0de111 |
if [[ -z "${TCAR_MODULE_ARGUMENTS}" ]];then
|
|
Alain Reguera Delgado |
0de111 |
TCAR_MODULE_ARGUMENTS=${PWD}
|
|
Alain Reguera Delgado |
615395 |
fi
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
0de111 |
# Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable.
|
|
Alain Reguera Delgado |
615395 |
if [[ ! -z ${ARGSS} ]] || [[ ! -z ${ARGSL} ]];then
|
|
Alain Reguera Delgado |
0de111 |
eval set -- "${TCAR_MODULE_ARGUMENTS}"
|
|
Alain Reguera Delgado |
0de111 |
TCAR_MODULE_ARGUMENTS=$(getopt -o "${ARGSS}" -l "${ARGSL}" \
|
|
Alain Reguera Delgado |
615395 |
-n "${TCAR_CLI_COMMAND} ($(cli_printCaller 2))" -- "${@}")
|
|
Alain Reguera Delgado |
615395 |
if [[ $? -ne 0 ]];then
|
|
Alain Reguera Delgado |
615395 |
cli_printMessage "`gettext "The argument verification failed."`" --as-error-line
|
|
Alain Reguera Delgado |
615395 |
fi
|
|
Alain Reguera Delgado |
615395 |
fi
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
}
|