|
|
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"
|
|
|
e3f199 |
|
|
|
e3f199 |
# Verify amount of files to process. If there is no one then there
|
|
|
e3f199 |
# is nothing else to do here.
|
|
|
2c195e |
if [[ "$FILES" == '' ]];then
|
|
|
e3f199 |
return
|
|
|
e3f199 |
fi
|
|
|
e3f199 |
|
|
|
0cb4af |
local ACTION="$2"
|
|
|
0cb4af |
local FORMAT="$3"
|
|
|
1dda8c |
local FILE=''
|
|
|
1dda8c |
local NEGATIVE=''
|
|
|
1dda8c |
local POSITIVE=''
|
|
|
1dda8c |
local COUNT=0
|
|
|
d1225f |
|
|
|
e3f199 |
# Replace spaces by new line.
|
|
|
e3f199 |
FILES=$(echo "$FILES" | sed -r "s! +!\n!g")
|
|
|
e3f199 |
|
|
|
a07e81 |
# Redefine total number of directories.
|
|
|
e3f199 |
COUNT=$(echo "$FILES" | wc -l)
|
|
|
0cb4af |
|
|
|
e3f199 |
# Redefine preamble messages based on action. At this point seems
|
|
|
e3f199 |
# to be some files to process so lets read ACTION to know what to
|
|
|
e3f199 |
# do with them.
|
|
|
0cb4af |
case $ACTION in
|
|
|
ba231b |
|
|
|
0cb4af |
'doCreate' )
|
|
|
1dda8c |
if [[ $FILES == '' ]];then
|
|
|
1dda8c |
NEGATIVE="`gettext "There is no entry to create."`"
|
|
|
1dda8c |
else
|
|
|
1dda8c |
POSITIVE="`ngettext "The following entry will be created" \
|
|
|
1dda8c |
"The following entries will be created" $COUNT`:"
|
|
|
1dda8c |
fi
|
|
|
0cb4af |
;;
|
|
|
0cb4af |
|
|
|
0cb4af |
'doDelete' )
|
|
|
1dda8c |
if [[ $FILES == '' ]];then
|
|
|
1dda8c |
NEGATIVE="`gettext "There is no file to delete."`"
|
|
|
1dda8c |
else
|
|
|
1dda8c |
POSITIVE="`ngettext "The following entry will be deleted" \
|
|
|
1dda8c |
"The following entries will be deleted" $COUNT`:"
|
|
|
1dda8c |
fi
|
|
|
0cb4af |
;;
|
|
|
0cb4af |
|
|
|
6dc5d4 |
'doLocale' )
|
|
|
1dda8c |
if [[ $FILES == '' ]];then
|
|
|
1dda8c |
NEGATIVE="`gettext "There is no file to locale."`"
|
|
|
1dda8c |
else
|
|
|
1dda8c |
POSITIVE="`ngettext "Translatable strings will be retrived from the following entry" \
|
|
|
1dda8c |
"Translatable strings will be retrived from the following entries" $COUNT`:"
|
|
|
1dda8c |
fi
|
|
|
6dc5d4 |
;;
|
|
|
6dc5d4 |
|
|
|
ba231b |
'doEdit' )
|
|
|
1dda8c |
if [[ $FILES == '' ]];then
|
|
|
1dda8c |
NEGATIVE="`gettext "There is no file to edit."`"
|
|
|
1dda8c |
else
|
|
|
1dda8c |
POSITIVE="`ngettext "The following file will be edited" \
|
|
|
1dda8c |
"The following files will be edited" $COUNT`:"
|
|
|
1dda8c |
fi
|
|
|
1dda8c |
;;
|
|
|
1dda8c |
|
|
|
1dda8c |
* )
|
|
|
1dda8c |
# Check list of files to process. If we have an empty
|
|
|
1dda8c |
# list of files, inform about that and stop the script
|
|
|
1dda8c |
# execution. Otherwise, check all files in the list to be
|
|
|
1dda8c |
# sure they are regular files.
|
|
|
1dda8c |
if [[ "$FILES" == '' ]];then
|
|
|
e310ce |
NEGATIVE="`gettext "There is no file to process."`"
|
|
|
1dda8c |
fi
|
|
|
ba231b |
;;
|
|
|
ba231b |
|
|
|
0cb4af |
esac
|
|
|
0cb4af |
|
|
|
0cb4af |
# Print preamble message.
|
|
|
0d4a3b |
if [[ $POSITIVE != '' ]] && [[ $NEGATIVE == '' ]];then
|
|
|
1dda8c |
cli_printMessage "$POSITIVE"
|
|
|
e3f199 |
for FILE in $FILES;do
|
|
|
e3f199 |
cli_printMessage "$FILE" "$FORMAT"
|
|
|
e3f199 |
done
|
|
|
1dda8c |
cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine'
|
|
|
0d4a3b |
elif [[ $POSITIVE == '' ]] && [[ $NEGATIVE != '' ]];then
|
|
|
e310ce |
cli_printMessage "$NEGATIVE" 'AsErrorLine'
|
|
|
1dda8c |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
1dda8c |
fi
|
|
|
0cb4af |
|
|
|
0cb4af |
}
|