Blame Scripts/Bash/Functions/cli_printMessage.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# cli_printMessage.sh -- This function outputs information in
4c79b5
# predifined formats. This function (cli_printMessage) is the standard
4c79b5
# way to output information inside centos-art.sh script.
4c79b5
#
7cd8e9
# cli_printMessage $1 $2
7cd8e9
# $1 --> The message you want to output.
7cd8e9
# $2 --> The message format.
4c79b5
#
843bac
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function cli_printMessage {
4c79b5
4c79b5
    # Define variables as local to avoid conflicts outside.
4c79b5
    local MESSAGE="$1"
4c79b5
    local FORMAT="$2"
cdebd1
    local Y=''
cdebd1
    local N=''
cdebd1
    local ANSWER=''
843bac
4c79b5
    # Reduce paths inside output messages. The main purpose for this
4c79b5
    # is to free horizontal space in output messages.
841480
    MESSAGE=$(echo "$MESSAGE" \
3b6828
        | sed -r 's!/home/centos/artwork/(trunk|branches|tags)/!\1/!g')
4c79b5
4c79b5
    # Remove blank spaces from lines' begining.
4c79b5
    MESSAGE=$(echo "$MESSAGE" | sed -r 's!^[[:space:]]+!!')
4c79b5
4c79b5
    # Define message formats.
4c79b5
    case $FORMAT in
4c79b5
4c79b5
        'AsHeadingLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo '----------------------------------------------------------------------'
843bac
                echo "$MESSAGE" | fmt --width=70
843bac
                echo '----------------------------------------------------------------------'
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsWarningLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo '----------------------------------------------------------------------'
843bac
                echo "`gettext "WARNING"`: $MESSAGE" | fmt --width=70
843bac
                echo '----------------------------------------------------------------------'
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsNoteLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo '----------------------------------------------------------------------'
843bac
                echo "`gettext "NOTE"`: $MESSAGE" | fmt --width=70
843bac
                echo '----------------------------------------------------------------------'
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsUpdatingLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Updating"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
9a2a67
        'AsDeletingLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Deleting"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsCheckingLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Checking"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsCreatingLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Creating"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsSavedAsLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Saved as"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsLinkToLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Linked to"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
6253fc
            ;;
6253fc
6253fc
        'AsMovedToLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Moved to"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsTranslationLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Translation"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
e92b23
            ;;
e92b23
e92b23
        'AsConfigurationLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Configuration"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
70c11c
        'AsPaletteLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "`gettext "Palette"`: $MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
70c11c
            ;;
70c11c
4c79b5
        'AsResponseLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "--> $MESSAGE"
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsRequestLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo -n "${MESSAGE}: "
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
        'AsYesOrNoRequestLine' )
cdebd1
            # Define positive answer.
cdebd1
            Y="`gettext "y"`"
cdebd1
cdebd1
            # Define negative answer.
cdebd1
            N="`gettext "N"`"
cdebd1
cdebd1
            # Define `yes or no' confirmation question.
843bac
            if [[ $FLAG_QUIET == 'false' ]] \
843bac
                && [[ $FLAG_YES == 'false' ]];then
843bac
                echo -n "$MESSAGE [${Y}/${N}]: "
843bac
                read ANSWER
843bac
            fi
843bac
843bac
            # Redefine answer based on answer flag.
843bac
            if [[ $FLAG_YES == 'true' ]];then
843bac
                ANSWER=${Y}
843bac
            fi
843bac
843bac
            # Verify answer.
4c79b5
            if [[ ! $ANSWER =~ "^${Y}" ]];then
4c79b5
                exit
4c79b5
            fi
4c79b5
            ;;
a44f77
843bac
        'AsErrorLine' )
a44f77
            # Add script name to message. We want to know where
218ca5
            # messages come from. The `--quiet' flag doesn't suppress
218ca5
            # error messages.
218ca5
            echo "${CLINAME}: ${MESSAGE}"
a44f77
            ;;
4c79b5
4c79b5
        'AsToKnowMoreLine' )
1f1b3c
            # This option receives the output of bash's caller builtin
1f1b3c
            # as message value, in order to produce the documentation
218ca5
            # entry automatically. The `--quiet' flag doesn't suppress
218ca5
            # `as to know more' messages.
ced9f7
            MESSAGE=$(dirname $(echo $MESSAGE | cut -d ' ' -f2-))
be93f6
            echo "----------------------------------------------------------------------"
bcde3a
            echo "`gettext "To know more, run the following command"`:"
dab966
            echo "centos-art manual --read='$MESSAGE'"
be93f6
            echo "----------------------------------------------------------------------"
6253fc
            exit # <-- ATTENTION: Do not remove this line. We use this
6253fc
                 #                case as convenction to end script
6253fc
                 #                execution.
6253fc
            ;;
6253fc
6253fc
        'AsRegularLine' )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "$MESSAGE" \
843bac
                    | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
843bac
            fi
4c79b5
            ;;
4c79b5
6253fc
        * )
843bac
            if [[ $FLAG_QUIET == 'false' ]];then
843bac
                echo "$MESSAGE"
843bac
            fi
4c79b5
            ;;
4c79b5
4c79b5
    esac
4c79b5
4c79b5
}