|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# cli_printActionPreamble -- This function standardizes the way
|
|
|
878a2b |
# preamble messages are printed out. Preamble messages are used before
|
|
|
878a2b |
# actions (e.g., file elimination, edition, creation, actualization,
|
|
|
878a2b |
# etc.) and provide a way for the user to control whether the action
|
|
|
878a2b |
# is performed or not.
|
|
|
878a2b |
#
|
|
|
03486a |
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is free software; you can redistribute it and/or modify
|
|
|
878a2b |
# it under the terms of the GNU General Public License as published by
|
|
|
878a2b |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
878a2b |
# your option) any later version.
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is distributed in the hope that it will be useful, but
|
|
|
878a2b |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
878a2b |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
878a2b |
# General Public License for more details.
|
|
|
878a2b |
#
|
|
|
878a2b |
# You should have received a copy of the GNU General Public License
|
|
|
878a2b |
# along with this program; if not, write to the Free Software
|
|
|
878a2b |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
878a2b |
#
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
# $Id$
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
|
|
|
878a2b |
function cli_printActionPreamble {
|
|
|
878a2b |
|
|
|
878a2b |
# Define short options.
|
|
|
878a2b |
local ARGSS=''
|
|
|
878a2b |
|
|
|
878a2b |
# Define long options.
|
|
|
878a2b |
local ARGSL='to-create,to-delete,to-locale,to-edit'
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize message.
|
|
|
878a2b |
local MESSAGE=''
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize message options.
|
|
|
878a2b |
local OPTION=''
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize file variable as local to avoid conflicts outside.
|
|
|
878a2b |
# We'll use the file variable later, to show the list of files
|
|
|
878a2b |
# that will be affected by the action.
|
|
|
878a2b |
local FILE=''
|
|
|
878a2b |
|
|
|
3a9ac2 |
# Initialize arguments with an empty value and set it as local
|
|
|
3a9ac2 |
# variable to this function scope. Doing this is very important to
|
|
|
3a9ac2 |
# avoid any clash with higher execution environments.
|
|
|
3a9ac2 |
local ARGUMENTS=''
|
|
|
3a9ac2 |
|
|
|
3a9ac2 |
# Prepare ARGUMENTS for getopt.
|
|
|
878a2b |
cli_parseArgumentsReDef "$@"
|
|
|
878a2b |
|
|
|
3a9ac2 |
# Redefine ARGUMENTS using getopt(1) command parser.
|
|
|
878a2b |
cli_parseArguments
|
|
|
878a2b |
|
|
|
878a2b |
# Redefine positional parameters using ARGUMENTS variable.
|
|
|
878a2b |
eval set -- "$ARGUMENTS"
|
|
|
878a2b |
|
|
|
878a2b |
# Define the location we want to apply verifications to.
|
|
|
878a2b |
local FILES=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!')
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize counter with total number of files.
|
|
|
878a2b |
local COUNT=$(echo $FILES | wc -l)
|
|
|
878a2b |
|
|
|
878a2b |
# Look for options passed through positional parameters.
|
|
|
878a2b |
while true;do
|
|
|
878a2b |
|
|
|
878a2b |
case "$1" in
|
|
|
878a2b |
|
|
|
878a2b |
--to-create )
|
|
|
878a2b |
if [[ $FILES == '--' ]];then
|
|
|
878a2b |
MESSAGE="`gettext "There is no entry to create."`"
|
|
|
878a2b |
OPTION='--as-error-line'
|
|
|
878a2b |
else
|
|
|
878a2b |
MESSAGE="`ngettext "The following entry will be created" \
|
|
|
878a2b |
"The following entries will be created" $COUNT`:"
|
|
|
878a2b |
OPTION=''
|
|
|
878a2b |
fi
|
|
|
878a2b |
shift 2
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
--to-delete )
|
|
|
878a2b |
if [[ $FILES == '--' ]];then
|
|
|
878a2b |
MESSAGE="`gettext "There is no file to delete."`"
|
|
|
878a2b |
OPTION='--as-error-line'
|
|
|
878a2b |
else
|
|
|
878a2b |
MESSAGE="`ngettext "The following entry will be deleted" \
|
|
|
878a2b |
"The following entries will be deleted" $COUNT`:"
|
|
|
878a2b |
OPTION=''
|
|
|
878a2b |
fi
|
|
|
878a2b |
shift 2
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
--to-locale )
|
|
|
878a2b |
if [[ $FILES == '--' ]];then
|
|
|
878a2b |
MESSAGE="`gettext "There is no file to locale."`"
|
|
|
878a2b |
OPTION='--as-error-line'
|
|
|
878a2b |
else
|
|
|
878a2b |
MESSAGE="`ngettext "Translatable strings will be retrived from the following entry" \
|
|
|
878a2b |
"Translatable strings will be retrived from the following entries" $COUNT`:"
|
|
|
878a2b |
OPTION=''
|
|
|
878a2b |
fi
|
|
|
878a2b |
shift 2
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
--to-edit )
|
|
|
878a2b |
if [[ $FILES == '--' ]];then
|
|
|
878a2b |
MESSAGE="`gettext "There is no file to edit."`"
|
|
|
878a2b |
OPTION='--as-error-line'
|
|
|
878a2b |
else
|
|
|
878a2b |
MESSAGE="`ngettext "The following file will be edited" \
|
|
|
878a2b |
"The following files will be edited" $COUNT`:"
|
|
|
878a2b |
OPTION=''
|
|
|
878a2b |
fi
|
|
|
878a2b |
shift 2
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
-- )
|
|
|
878a2b |
if [[ $FILES == '--' ]];then
|
|
|
878a2b |
MESSAGE="`gettext "There is no file to process."`"
|
|
|
878a2b |
OPTION='--as-error-line'
|
|
|
878a2b |
else
|
|
|
878a2b |
MESSAGE="`ngettext "The following file will be processed" \
|
|
|
878a2b |
"The following files will be processed" $COUNT`:"
|
|
|
878a2b |
OPTION=''
|
|
|
878a2b |
fi
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
esac
|
|
|
878a2b |
done
|
|
|
878a2b |
|
|
|
878a2b |
# Print out the preamble message.
|
|
|
db214c |
cli_printMessage "${MESSAGE}" "${OPTION}" --as-stdout-line
|
|
|
878a2b |
for FILE in $FILES;do
|
|
|
878a2b |
cli_printMessage "$FILE" --as-response-line
|
|
|
878a2b |
done
|
|
|
db214c |
cli_printMessage "`gettext "Do you want to continue?"`" --as-yesornorequest-line
|
|
|
878a2b |
|
|
|
878a2b |
}
|