|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# cli_printMessage.sh -- This function standardizes the way messages
|
|
|
878a2b |
|
|
|
878a2b |
#
|
|
|
878a2b |
# Copyright (C) 2009, 2010, 2011 The CentOS Project
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is free software; you can redistribute it and/or modify
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
#
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
# General Public License for more details.
|
|
|
878a2b |
#
|
|
|
878a2b |
|
|
|
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_printMessage {
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
if [[ "$FLAG_QUIET" == 'true' ]];then
|
|
|
878a2b |
return
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
local MESSAGE="$1"
|
|
|
878a2b |
local FORMAT="$2"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
if [[ $MESSAGE == '' ]];then
|
|
|
878a2b |
cli_printMessage "`gettext "The message cannot be empty."`" --as-error-line
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
local MESSAGE_WIDTH=66
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
# cli_parseArgumentsReDef, and we need to reverse it back here
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
MESSAGE=$(echo $MESSAGE | sed -e "s/\\\0x27/'/g")
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
MESSAGE=$(echo $MESSAGE | sed -e 's!^[[:space:]]+!!')
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
case "$FORMAT" in
|
|
|
878a2b |
|
|
|
878a2b |
--as-separator-line )
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
MESSAGE=$(\
|
|
|
878a2b |
until [[ $MESSAGE_WIDTH -eq 0 ]];do
|
|
|
878a2b |
echo -n "$MESSAGE"
|
|
|
878a2b |
MESSAGE_WIDTH=$(($MESSAGE_WIDTH - 1))
|
|
|
878a2b |
done)
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
echo "$MESSAGE" > /dev/stderr
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-banner-line )
|
|
|
878a2b |
cli_printMessage '-' --as-separator-line
|
|
|
878a2b |
cli_printMessage "$MESSAGE"
|
|
|
878a2b |
cli_printMessage '-' --as-separator-line
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-cropping-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Cropping from"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-tuningup-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Tuning-up"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-checking-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Checking"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-creating-line | --as-updating-line )
|
|
|
878a2b |
if [[ -a "$MESSAGE" ]];then
|
|
|
878a2b |
cli_printMessage "`gettext "Updating"`: $MESSAGE"
|
|
|
878a2b |
else
|
|
|
878a2b |
cli_printMessage "`gettext "Creating"`: $MESSAGE"
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-deleting-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Deleting"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-reading-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Reading"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-savedas-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Saved as"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-linkto-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Linked to"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-movedto-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Moved to"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-translation-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Translation"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-validating-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Validating"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-template-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Template"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-configuration-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Configuration"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-palette-line )
|
|
|
878a2b |
cli_printMessage "`gettext "Palette"`: $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-response-line )
|
|
|
878a2b |
cli_printMessage "--> $MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-request-line )
|
|
|
878a2b |
cli_printMessage "${MESSAGE}:\040" --as-notrailingnew-line
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-selection-line )
|
|
|
878a2b |
local NAME=''
|
|
|
878a2b |
select NAME in ${MESSAGE};do
|
|
|
878a2b |
echo $NAME
|
|
|
878a2b |
break
|
|
|
878a2b |
done
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-error-line )
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
local ORIGIN="$(caller 1 | gawk '{ print $2 " " $1 }')"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
cli_printMessage "${CLI_PROGRAM} (${ORIGIN}): $MESSAGE" --as-stderr-line
|
|
|
878a2b |
cli_printMessage "${CLI_FUNCDIRNAM}" --as-toknowmore-line
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-toknowmore-line )
|
|
|
878a2b |
cli_printMessage '-' --as-separator-line
|
|
|
878a2b |
cli_printMessage "`gettext "To know more, run the following command"`:"
|
|
|
878a2b |
cli_printMessage "centos-art help --read trunk/Scripts/Functions/$MESSAGE"
|
|
|
878a2b |
cli_printMessage '-' --as-separator-line
|
|
|
878a2b |
exit # <-- ATTENTION: Do not remove this line. We use this
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-yesornorequest-line )
|
|
|
878a2b |
|
|
|
878a2b |
local Y="`gettext "yes"`"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
local N="`gettext "no"`"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
local ANSWER=${N}
|
|
|
878a2b |
|
|
|
878a2b |
if [[ $FLAG_ANSWER == 'true' ]];then
|
|
|
878a2b |
|
|
|
878a2b |
ANSWER=${Y}
|
|
|
878a2b |
|
|
|
878a2b |
else
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
cli_printMessage "$MESSAGE [${Y}/${N}]:\040" --as-notrailingnew-line
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
read ANSWER
|
|
|
878a2b |
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
# script flow to continue. Otherwise, if something
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
if [[ ! ${ANSWER} =~ "^${Y}" ]];then
|
|
|
878a2b |
exit
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-notrailingnew-line )
|
|
|
878a2b |
echo -e -n "$MESSAGE" > /dev/stderr
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-stdout-line )
|
|
|
878a2b |
echo "$MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
--as-stderr-line )
|
|
|
878a2b |
echo "$MESSAGE"
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
* )
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
# paths in order to free horizontal space on final output
|
|
|
878a2b |
|
|
|
878a2b |
echo "$MESSAGE" | sed -r \
|
|
|
878a2b |
-e "s!${CLI_WRKCOPY}/(trunk|branches|tags)/!\1/!g" \
|
|
|
878a2b |
| awk 'BEGIN { FS=": " }
|
|
|
878a2b |
{
|
|
|
878a2b |
if ( $0 ~ /^-+$/ )
|
|
|
878a2b |
print $0
|
|
|
878a2b |
else
|
|
|
878a2b |
printf "%-15s\t%s\n", $1, $2
|
|
|
878a2b |
}
|
|
|
878a2b |
END {}' > /dev/stderr
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
esac
|
|
|
878a2b |
|
|
|
878a2b |
}
|