From c62219da30c9853ab963334dfde515db1b75474c Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Mar 14 2011 23:16:23 +0000 Subject: Update cli_printMessage.sh: - Remove the 'for' loop we previously added in order to make this function to accept more than one message thorugh first function argument. That configuration seems to work when messages do not include white spaces inside (e.g., messages are a path), but when individual messages contain spaces as part of themselves (e.g., error messages) everything is broken into words because we didn't escape messages values when we built the loop. On the other hand, if we escape messages in the loop, paths passed as individual messages are concatenated and the format we expect isn't shown. - So, to eliminate such ambiguity, this function only accepts one message in order to output it in a predefined format. If you eant to print several lines, then create loop through files and call this function inside the loop to print individual files with predefined formats. --- diff --git a/Scripts/Bash/Cli/Functions/cli_printMessage.sh b/Scripts/Bash/Cli/Functions/cli_printMessage.sh index a579541..9cf3ec3 100755 --- a/Scripts/Bash/Cli/Functions/cli_printMessage.sh +++ b/Scripts/Bash/Cli/Functions/cli_printMessage.sh @@ -32,159 +32,149 @@ function cli_printMessage { return fi - local MESSAGES="$1" + local MESSAGE="$1" local FORMAT="$2" - local MESSAGE='' - - # Let processing more than one message. There is no need to - # create loops outside this function to process more than one - # message. Instead, pass the list of messages to this function. - # This may save some memory when the `--quiet' option is used. - for MESSAGE in "$MESSAGES";do - - # Reduce paths inside output messages. The main purpose for - # this is to free horizontal space in output messages. - MESSAGE=$(echo "$MESSAGE" \ - | sed -r "s!${HOME}/artwork/(trunk|branches|tags)/!\1/!g") - - # Remove blank spaces from lines' begining. - MESSAGE=$(echo "$MESSAGE" | sed -r 's!^[[:space:]]+!!') - - # Define message formats. - case $FORMAT in - - 'AsUpdatingLine' ) - cli_printMessage "`gettext "Updating"`: $MESSAGE" - ;; - - 'AsDeletingLine' ) - cli_printMessage "`gettext "Deleting"`: $MESSAGE" - ;; - - 'AsCheckingLine' ) - cli_printMessage "`gettext "Checking"`: $MESSAGE" - ;; - - 'AsCreatingLine' ) - cli_printMessage "`gettext "Creating"`: $MESSAGE" - ;; - - 'AsReadingLine' ) - cli_printMessage "`gettext "Reading"`: $MESSAGE" - ;; - - 'AsSavedAsLine' ) - cli_printMessage "`gettext "Saved as"`: $MESSAGE" - ;; - - 'AsLinkToLine' ) - cli_printMessage "`gettext "Linked to"`: $MESSAGE" - ;; - - 'AsMovedToLine' ) - cli_printMessage "`gettext "Moved to"`: $MESSAGE" - ;; - - 'AsTranslationLine' ) - cli_printMessage "`gettext "Translation"`: $MESSAGE" - ;; - - 'AsDesignLine' ) - cli_printMessage "`gettext "Design"`: $MESSAGE" - ;; - - 'AsConfigurationLine' ) - cli_printMessage "`gettext "Configuration"`: $MESSAGE" - ;; - - 'AsPaletteLine' ) - cli_printMessage "`gettext "Palette"`: $MESSAGE" - ;; - - 'AsResponseLine' ) - cli_printMessage "--> $MESSAGE" - ;; - - 'AsRequestLine' ) - cli_printMessage "${MESSAGE}: " 'AsNoTrailingNewLine' - ;; - - 'AsErrorLine' ) - # This option is used to print error messsages. - echo "${CLI_PROGRAM}: ${MESSAGE}" > /dev/stderr - ;; - - 'AsToKnowMoreLine' ) - # This option receives the output of bash's caller - # built-in as message value and produces the documentation - # entry from it. - MESSAGE=$(dirname "$(echo $MESSAGE | cut -d ' ' -f2-)") - cli_printMessage '-' 'AsSeparatorLine' - cli_printMessage "`gettext "To know more, run the following command"`:" - cli_printMessage "centos-art manual --read='$MESSAGE'" - cli_printMessage '-' 'AsSeparatorLine' - exit # <-- ATTENTION: Do not remove this line. We use this - # option as convenction to end script - # execution. - ;; - - 'AsYesOrNoRequestLine' ) - # Define positive answer. - local Y="`gettext "yes"`" + # Reduce paths inside output messages. The main purpose for + # this is to free horizontal space in output messages. + MESSAGE=$(echo "$MESSAGE" \ + | sed -r "s!${HOME}/artwork/(trunk|branches|tags)/!\1/!g") + + # Remove blank spaces from lines' begining. + MESSAGE=$(echo "$MESSAGE" | sed -r 's!^[[:space:]]+!!') + + # Define message formats. + case $FORMAT in + + 'AsUpdatingLine' ) + cli_printMessage "`gettext "Updating"`: $MESSAGE" + ;; + + 'AsDeletingLine' ) + cli_printMessage "`gettext "Deleting"`: $MESSAGE" + ;; + + 'AsCheckingLine' ) + cli_printMessage "`gettext "Checking"`: $MESSAGE" + ;; + + 'AsCreatingLine' ) + cli_printMessage "`gettext "Creating"`: $MESSAGE" + ;; + + 'AsReadingLine' ) + cli_printMessage "`gettext "Reading"`: $MESSAGE" + ;; + + 'AsSavedAsLine' ) + cli_printMessage "`gettext "Saved as"`: $MESSAGE" + ;; + + 'AsLinkToLine' ) + cli_printMessage "`gettext "Linked to"`: $MESSAGE" + ;; + + 'AsMovedToLine' ) + cli_printMessage "`gettext "Moved to"`: $MESSAGE" + ;; + + 'AsTranslationLine' ) + cli_printMessage "`gettext "Translation"`: $MESSAGE" + ;; + + 'AsDesignLine' ) + cli_printMessage "`gettext "Design"`: $MESSAGE" + ;; + + 'AsConfigurationLine' ) + cli_printMessage "`gettext "Configuration"`: $MESSAGE" + ;; + + 'AsPaletteLine' ) + cli_printMessage "`gettext "Palette"`: $MESSAGE" + ;; + + 'AsResponseLine' ) + cli_printMessage "--> $MESSAGE" + ;; + + 'AsRequestLine' ) + cli_printMessage "${MESSAGE}: " 'AsNoTrailingNewLine' + ;; + + 'AsErrorLine' ) + # This option is used to print error messsages. + echo "${CLI_PROGRAM}: ${MESSAGE}" > /dev/stderr + ;; + + 'AsToKnowMoreLine' ) + # This option receives the output of bash's caller built-in as + # message value and produces the documentation entry from it. + MESSAGE=$(dirname "$(echo $MESSAGE | cut -d ' ' -f2-)") + cli_printMessage '-' 'AsSeparatorLine' + cli_printMessage "`gettext "To know more, run the following command"`:" + cli_printMessage "centos-art manual --read='$MESSAGE'" + cli_printMessage '-' 'AsSeparatorLine' + exit # <-- ATTENTION: Do not remove this line. We use this + # option as convenction to end script + # execution. + ;; + + 'AsYesOrNoRequestLine' ) - # Define negative answer. - local N="`gettext "no"`" + # Define positive answer. + local Y="`gettext "yes"`" - # Define default answer. - local ANSWER=${FLAG_ANSWER} + # Define negative answer. + local N="`gettext "no"`" - if [[ $ANSWER == 'false' ]];then + # Define default answer. + local ANSWER=${FLAG_ANSWER} - # Print the question. - cli_printMessage "$MESSAGE [${Y}/${N}]: " 'AsNoTrailingNewLine' + if [[ $ANSWER == 'false' ]];then - # Redefine default answer based on user's input. - read ANSWER + # Print the question. + cli_printMessage "$MESSAGE [${Y}/${N}]: " 'AsNoTrailingNewLine' - fi + # Redefine default answer based on user's input. + read ANSWER - # Verify user's answer. Only positive answer let the - # script flow to continue. Otherwise, if something - # different from possitive answer is passed, the - # script terminates its execution immediatly. - if [[ ! ${ANSWER} =~ "^${Y}" ]];then - exit - fi - ;; + fi - 'AsSeparatorLine' ) + # Verify user's answer. Only positive answer let the script + # flow to continue. Otherwise, if something different from + # possitive answer is passed, the script terminates its + # execution immediatly. + if [[ ! ${ANSWER} =~ "^${Y}" ]];then + exit + fi + ;; - # Define separator width. - local MAX=70 + 'AsSeparatorLine' ) - # Draw separator. - until [[ $MAX -eq 0 ]];do - printf "${MESSAGE}" > /dev/stderr - MAX=$(($MAX - 1)) - done + # Define separator width. + local MAX=70 - # Output newline to end separator. - echo "" > /dev/stderr - ;; + # Draw separator. + until [[ $MAX -eq 0 ]];do + printf "${MESSAGE}" > /dev/stderr + MAX=$(($MAX - 1)) + done - 'AsNoTrailingNewLine' ) - printf "$MESSAGE" > /dev/stderr - ;; + # Output newline to end separator. + echo "" > /dev/stderr + ;; - 'AsRegularLine' | * ) - echo "$MESSAGE" \ - | awk -f ${CLI_BASEDIR}/Styles/output_forTwoColumns.awk \ - > /dev/stderr - ;; + 'AsNoTrailingNewLine' ) + printf "$MESSAGE" > /dev/stderr + ;; - esac + 'AsRegularLine' | * ) + echo "$MESSAGE" \ + | awk -f ${CLI_BASEDIR}/Styles/output_forTwoColumns.awk \ + > /dev/stderr + ;; - done + esac }