Blame Scripts/Functions/cli_printActionPreamble.sh

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