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
0cb4af
    local DIR=''
ba231b
    local DIRS="$1"
0cb4af
    local ACTION="$2"
0cb4af
    local FORMAT="$3"
0cb4af
    local COUNT_DIRS=0
0cb4af
a07e81
    # Redefine total number of directories.
a07e81
    COUNT_DIRS=$(echo "$DIRS" | 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" \
0cb4af
            "The following entries will be created" $COUNT_DIRS`:"
0cb4af
            ;;
0cb4af
0cb4af
        'doDelete' )
0cb4af
            ACTION="`ngettext "The following entry will be deleted" \
0cb4af
            "The following entries will be deleted" $COUNT_DIRS`:"
0cb4af
            ;;
0cb4af
6dc5d4
        'doLocale' )
ba231b
            ACTION="`ngettext "Translatable strings will be retrived from the following entry" \
6dc5d4
            "Translatable strings will be retrived from the following entries" $COUNT_DIRS`:"
6dc5d4
            ;;
6dc5d4
ba231b
        'doEdit' )
ba231b
            ACTION="`ngettext "The following file will be edited" \
ba231b
            "The following files will be edited" $COUNT_DIRS`:"
ba231b
            ;;
ba231b
0cb4af
        * )
0cb4af
            cli_printMessage "cli_printActionPreamble: `gettext "The second argument is not valid."`" 'AsErrorLine'
0cb4af
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
0cb4af
            ;;
0cb4af
    esac
0cb4af
0cb4af
    # Print preamble message.
0cb4af
    cli_printMessage "$ACTION"
0cb4af
    for DIR in $(echo $DIRS);do
0cb4af
        cli_printMessage "$DIR" "$FORMAT"
0cb4af
    done
0cb4af
    cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine'
0cb4af
0cb4af
}