Blame Scripts/Bash/Functions/cli_printActionPreamble.sh

0cb4af
#!/bin/bash
0cb4af
#
0cb4af
# cli_printActionPreamble -- This function standardizes action
0cb4af
# preamble messages. Action preamble messages provides a confirmation
0cb4af
# message that illustrate what files will be affected in the action.
0cb4af
#
0cb4af
# Generally, actions are applied to parent directories. Each parent
0cb4af
# directory has parallel directories associated. If one parent
0cb4af
# directory is created/deleted, the parallel directories associated do
0cb4af
# need to be created/deleted too.
0cb4af
#
0cb4af
# Copyright (C) 2009-2011 Alain Reguera Delgado
0cb4af
# 
0cb4af
# This program is free software; you can redistribute it and/or
0cb4af
# modify it under the terms of the GNU General Public License as
0cb4af
# published by the Free Software Foundation; either version 2 of the
0cb4af
# License, or (at your option) any later version.
0cb4af
# 
0cb4af
# This program is distributed in the hope that it will be useful, but
0cb4af
# 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
0cb4af
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
0cb4af
# USA.
0cb4af
# 
0cb4af
# ----------------------------------------------------------------------
0cb4af
# $Id$
0cb4af
# ----------------------------------------------------------------------
0cb4af
0cb4af
function cli_printActionPreamble {
0cb4af
98e44c
    local FILES="$1"
0cb4af
    local ACTION="$2"
0cb4af
    local FORMAT="$3"
98e44c
98e44c
    # Check list of files to process. If we have an empty list of
98e44c
    # files, inform about it and stop script execution.
98e44c
    if [[ "$FILES" == '' ]];then
98e44c
        cli_printMessage "`gettext "There is no file to process."`" 'AsErrorLine'
98e44c
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
98e44c
    fi
98e44c
98e44c
    # Verify function parameters. If no action or format is passed to
98e44c
    # this function there is nothing else to do here. This
98e44c
    # verification should be _after_ checking list of files to
98e44c
    # process, so checking list of files to process take place even if
98e44c
    # no preamble message is printed out.
98e44c
    if [[ $# -lt 2 ]];then
98e44c
        return
98e44c
    fi
98e44c
98e44c
    local FILE=''
98e44c
    local COUNT=0
0cb4af
a07e81
    # Redefine total number of directories.
98e44c
    COUNT=$(echo "$FILES" | sed -r "s! +!\n!g" | wc -l)
0cb4af
0cb4af
    # Redefine preamble messages based on action.
0cb4af
    case $ACTION in
ba231b
0cb4af
        'doCreate' )
0cb4af
            ACTION="`ngettext "The following entry will be created" \
98e44c
            "The following entries will be created" $COUNT`:"
0cb4af
            ;;
0cb4af
0cb4af
        'doDelete' )
0cb4af
            ACTION="`ngettext "The following entry will be deleted" \
98e44c
            "The following entries will be deleted" $COUNT`:"
0cb4af
            ;;
0cb4af
6dc5d4
        'doLocale' )
ba231b
            ACTION="`ngettext "Translatable strings will be retrived from the following entry" \
98e44c
            "Translatable strings will be retrived from the following entries" $COUNT`:"
6dc5d4
            ;;
6dc5d4
ba231b
        'doEdit' )
ba231b
            ACTION="`ngettext "The following file will be edited" \
98e44c
            "The following files will be edited" $COUNT`:"
ba231b
            ;;
ba231b
0cb4af
    esac
0cb4af
0cb4af
    # Print preamble message.
0cb4af
    cli_printMessage "$ACTION"
98e44c
    for FILE in $FILES;do
98e44c
        cli_printMessage "$FILE" "$FORMAT"
0cb4af
    done
0cb4af
    cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine'
0cb4af
0cb4af
}