diff --git a/Scripts/Bash/Cli/Functions/Render/render.sh b/Scripts/Bash/Cli/Functions/Render/render.sh index a47c841..7ff1c6f 100644 --- a/Scripts/Bash/Cli/Functions/Render/render.sh +++ b/Scripts/Bash/Cli/Functions/Render/render.sh @@ -26,19 +26,15 @@ function render { - # Define default value to target flag. The target flag (--to) - # controls final destination used by copy related actions. - local FLAG_TO='' + # Define release number flag. The relesase number flag + # (--releasever) specifies the release number identity images are + # rendered for. By default no release number is used. + local FLAG_RELEASEVER='' - # Define release number flag. The relesase number flag (--release) - # specifies the release number identity images are rendered for. - # By default no release number is used. - local FLAG_RELEASE='' - - # Define architecture flag. The architecture flag (--architecture) + # Define architecture flag. The architecture flag (--basearch) # specifies the architecture type identity images are rendered # for. By default no architecture type is used. - local FLAG_ARCHITECTURE='' + local FLAG_BASEARCH='' # Define theme model flag. The theme model flag (--theme-model) # specifies the theme model used when no one is specified. @@ -54,7 +50,43 @@ function render { # upon images produced. By default there is no grouping action. local FLAG_GROUPED_BY='' - # Define rendition actions. + # Interpret arguments and options passed through command-line. render_getArguments + # Redefine positional parameters using ARGUMENTS. At this point, + # option arguments have been removed from ARGUMENTS variable and + # only non-option arguments remain in it. + eval set -- "$ARGUMENTS" + + # Read arguments and build the action value from them. As + # convenction, we use non-option arguments to define the action + # value (ACTIONVAL) variable. + for ACTIONVAL in "$@";do + + if [[ $ACTIONVAL == '--' ]];then + continue + fi + + # Check action value. Be sure the action value matches the + # convenctions defined for source locations inside the working + # copy. + cli_checkRepoDirSource + + # Syncronize changes between repository and working copy. At + # this point, changes in the repository are merged in the + # working copy and changes in the working copy committed up to + # repository. + cli_syncroRepoChanges + + # Execute base-rendition flow. + eval ${FUNCNAM}_doBaseActions + + # Commit changes from working copy to central repository only. + # At this point, changes in the repository are not merged in + # the working copy, but chages in the working copy do are + # committed up to repository. + cli_commitRepoChanges + + done + } diff --git a/Scripts/Bash/Cli/Functions/Render/render_getArguments.sh b/Scripts/Bash/Cli/Functions/Render/render_getArguments.sh index 7723152..8bcb62a 100644 --- a/Scripts/Bash/Cli/Functions/Render/render_getArguments.sh +++ b/Scripts/Bash/Cli/Functions/Render/render_getArguments.sh @@ -30,13 +30,12 @@ function render_getArguments { local ARGSS="" # Define long options we want to support. - local ARGSL="render:,releasever:,basearch:,copy:,to:,convert-to:,group-by:,theme-model:" + local ARGSL="filter:,quiet,answer:,dont-commit-changes,releasever:,basearch:,convert-to:,group-by:,theme-model:" - # Parse arguments using getopt(1) command parser. + # Redefine ARGUMENTS variable using getopt output. cli_doParseArguments - # Reset positional parameters using output from (getopt) argument - # parser. + # Redefine positional parameters using ARGUMENTS variable. eval set -- "$ARGUMENTS" # Look for options passed through command-line. @@ -44,9 +43,30 @@ function render_getArguments { case "$1" in + --filter ) + FLAG_FILTER="$2" + shift 2 + ;; + + --quiet ) + FLAG_QUIET="true" + FLAG_DONT_COMMIT_CHANGES="true" + shift 1 + ;; + + --answer ) + FLAG_ANSWER="$2" + shift 2 + ;; + + --dont-commit-changes ) + FLAG_DONT_COMMIT_CHANGES="true" + shift 1 + ;; + --releasever ) - FLAG_RELEASE="$2" - if [[ ! $FLAG_RELEASE =~ $(cli_getPathComponent '--release-pattern') ]];then + FLAG_RELEASEVER="$2" + if [[ ! $FLAG_RELEASEVER =~ $(cli_getPathComponent '--release-pattern') ]];then cli_printMessage "`gettext "The release version provided is not supported."`" 'AsErrorLine' cli_printMessage "$(caller)" 'AsToKnowMoreLine' fi @@ -54,19 +74,14 @@ function render_getArguments { ;; --basearch ) - FLAG_ARCHITECTURE="$2" - if [[ ! $FLAG_ARCHITECTURE =~ $(cli_getPathComponent '--architecture-pattern') ]];then + FLAG_BASEARCH="$2" + if [[ ! $FLAG_BASEARCH =~ $(cli_getPathComponent '--architecture-pattern') ]];then cli_printMessage "`gettext "The architecture provided is not supported."`" 'AsErrorLine' cli_printMessage "$(caller)" 'AsToKnowMoreLine' fi shift 2 ;; - --to ) - FLAG_TO="$2" - shift 2 - ;; - --convert-to ) FLAG_CONVERT_TO="$2" shift 2 @@ -83,35 +98,11 @@ function render_getArguments { ;; * ) - # Break options loop. break esac done - # Read remaining arguments and build the action value from them. - # At this point all options should be processed. - for ACTIONVAL in "$@";do - - if [[ $ACTIONVAL == '--' ]];then - continue - fi - - # Check action value. Be sure the action value matches the - # convenctions defined for source locations inside the working - # copy. - cli_checkRepoDirSource - - # Syncronize changes between the working copy and the central - # repository to bring down changes. - cli_syncroRepoChanges - - # Execute base-rendition flow. - eval ${FUNCNAM}_doBaseActions - - # Syncronize changes between the working copy and the central - # repository to commit up changes. - cli_commitRepoChanges - - done + # Redefine ARGUMENTS variable using current positional parameters. + cli_doParseArgumentsReDef "$@" } diff --git a/Scripts/Bash/Cli/Functions/Render/render_getDirOutput.sh b/Scripts/Bash/Cli/Functions/Render/render_getDirOutput.sh index bc664a3..9356d3b 100644 --- a/Scripts/Bash/Cli/Functions/Render/render_getDirOutput.sh +++ b/Scripts/Bash/Cli/Functions/Render/render_getDirOutput.sh @@ -37,7 +37,7 @@ function render_getDirOutput { # Redefine base output directory to introduce specific information # like release number, architecture, etc. - OUTPUT=${OUTPUT}/${FLAG_RELEASE}/${FLAG_ARCHITECTURE} + OUTPUT=${OUTPUT}/${FLAG_RELEASEVER}/${FLAG_BASEARCH} # Define whether to use or not locale-specific directory to store # content, using current locale information as reference. As diff --git a/Scripts/Bash/Cli/Functions/cli.sh b/Scripts/Bash/Cli/Functions/cli.sh index 0d36085..84ca306 100644 --- a/Scripts/Bash/Cli/Functions/cli.sh +++ b/Scripts/Bash/Cli/Functions/cli.sh @@ -34,34 +34,32 @@ function cli { local FUNCDIRNAM='' local FUNCSCRIPT='' local FUNCCONFIG='' - local ACTIONNAM='' local ACTIONVAL='' local ARGUMENTS='' + # Initialize default value to filter flag. The filter flag + # (--filter) is used mainly to reduce the number of files to + # process. The value of this variable is interpreted as + # egrep-posix regular expression. By default, everything matches. + local FLAG_FILTER='.+' + # Initialize default value to verbosity flag. The verbosity flag # (--quiet) controls whether centos-art.sh script prints messages - # or not. + # or not. By default, all messages are printed out. local FLAG_QUIET='false' # Initialize default value to answer flag. The answer flag # (--answer) controls whether centos-art.sh script does or does - # not pass confirmation request points. By default it doesn't. + # not pass confirmation request points. By default, it doesn't. local FLAG_ANSWER='false' - # Initialize default value to filter flag. The filter flag - # (--filter) is used mainly to reduce the number of files to - # process. The value of this variable is interpreted as - # egrep-posix regular expression. As initial value, we use a - # regular expression that matches everything. - local FLAG_FILTER='.+' - # Initialize default value to don't commit changes flag. The don't # commit changes flag (--dont-commit-changes) controls whether - # centos-art.sh script syncronizes changes between Subversion - # central repository and working copy. + # centos-art.sh script syncronizes changes between the central + # repository and the working copy. By default, it does. local FLAG_DONT_COMMIT_CHANGES='false' - # Redefine positional parameters stored inside ARGUMENTS variable. + # Redefine ARGUMENTS variable using current positional parameters. cli_doParseArgumentsReDef "$@" # Define function directory (FUNCDIR). The directory path where @@ -79,8 +77,8 @@ function cli { # Define function file name. FUNCSCRIPT=${FUNCDIR}/${FUNCDIRNAM}/${FUNCNAM}.sh - # Check function script existence. - cli_checkFiles $FUNCSCRIPT 'f' + # Check function script execution rights. + cli_checkFiles $FUNCSCRIPT 'x' # Define function configuration directory. The function # configuration directory is used to store functionality's @@ -92,19 +90,15 @@ function cli { # start counting from second argument (inclusive) on. shift 1 - # Redefine positional parameters stored inside ARGUMENTS variable. + # Redefine ARGUMENTS using current positional parameters. cli_doParseArgumentsReDef "$@" - # Parse positional parameters to retrive the value of common - # arguments (e.g., --answer-yes, --filter, --quiet, etc.). - cli_doParseArgumentsCommon - # Define default text editors used by centos-art.sh script. if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then EDITOR='/usr/bin/vim' fi - # Check text editor execution rights. + # Check text editor execution rights. cli_checkFiles $EDITOR 'x' # Go for function initialization. Keep the cli_getFunctions diff --git a/Scripts/Bash/Cli/Functions/cli_commitRepoChanges.sh b/Scripts/Bash/Cli/Functions/cli_commitRepoChanges.sh index f774a50..792d7d0 100755 --- a/Scripts/Bash/Cli/Functions/cli_commitRepoChanges.sh +++ b/Scripts/Bash/Cli/Functions/cli_commitRepoChanges.sh @@ -27,8 +27,8 @@ function cli_commitRepoChanges { - # Verify don't commit changes flag. - if [[ $FLAG_DONT_COMMIT_CHANGES != 'false' ]];then + # Verify `--dont-commit-changes' option. + if [[ $FLAG_DONT_COMMIT_CHANGES == 'true' ]];then return fi diff --git a/Scripts/Bash/Cli/Functions/cli_doParseArgumentsCommon.sh b/Scripts/Bash/Cli/Functions/cli_doParseArgumentsCommon.sh deleted file mode 100755 index e31d91f..0000000 --- a/Scripts/Bash/Cli/Functions/cli_doParseArgumentsCommon.sh +++ /dev/null @@ -1,199 +0,0 @@ -#!/bin/bash -# -# cli_doParseArgumentsCommon.sh -- This function parses positional -# parameters to divide arguments in common argumetns and specific -# arguments. Common arguments might be used by all specific -# functionalities. There is no need to have all common argument -# definitions duplicated in each specific functionality individually. -# Once the value of common arguments have been retrived in FLAG_ -# variables they are removed from ARGUMENTS positional parameters, in -# order to leave the specific arguments that specific functionalities -# most interpret. -# -# Copyright (C) 2009-2011 Alain Reguera Delgado -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function cli_doParseArgumentsCommon { - - local -a SHORT - local -a LONG - local -a REQUIRED - local ARGUMENT='' - local ARGUMENTS_DEFAULT='' - local COMMONS='' - local COMMON='' - local ARGSS='' - local ARGSL='' - local PATTERN='' - local COUNT=0 - - # Define local array to store short definition of common arguments. - SHORT[0]='f' - SHORT[1]='q' - SHORT[2]='y' - SHORT[3]='c' - - # Define local array to store long definition of common arguments. - LONG[0]='filter' - LONG[1]='quiet' - LONG[2]='answer' - LONG[3]='dont-commit-changes' - - # Define local array to store definition of whether the common - # argument is required [one colon], optional [two colons] or not - # required at all [empty]). - REQUIRED[0]=':' - REQUIRED[1]='' - REQUIRED[2]=':' - REQUIRED[3]='' - - # Save default arguments passed to centos-art.sh command-line. - # Since ARGUMENTS variable is used as convenction when arguments - # are redefined (see cli_doParseArgumentsReDef), it is required to - # use an intermediate-pattern variable in order to create the - # common and non-comon arguments information from it. - ARGUMENTS_DEFAULT=$ARGUMENTS - - # Build list of common arguments. - for ARGUMENT in $ARGUMENTS_DEFAULT;do - - while [[ $COUNT -lt ${#LONG[*]} ]];do - - # Define option pattern. - PATTERN="^'(--${LONG[$COUNT]}|-${SHORT[$COUNT]})" - - # Check argument against common argument pattern. - if [[ $ARGUMENT =~ "${PATTERN}" ]];then - if [[ $COMMONS == '' ]];then - COMMONS="${ARGUMENT}" - else - COMMONS="${COMMONS} ${ARGUMENT}" - fi - fi - - # Increment counter. - COUNT=$(($COUNT + 1)) - - done - - # Reset counter. - COUNT=0 - - done - - # Reset positional paramenters to start using common arguments and - # this way be able of performing common arguments verification - # independently from non-common arguments verification (which is - # done inside specific functionalities). - eval set -- "$COMMONS" - - # Redefine positional parameters stored inside ARGUMENTS variable - # to use common arguments only. - cli_doParseArgumentsReDef "$@" - - # Define short and long arguments variables using getopt format. - # This information is passed to getopt in order to now which the - # common arguments are. - while [[ $COUNT -lt ${#LONG[*]} ]];do - - # Define short arguments. - if [[ $ARGSS == '' ]];then - ARGSS=${SHORT[$COUNT]}${REQUIRED[$COUNT]} - else - ARGSS="${ARGSS},${SHORT[$COUNT]}${REQUIRED[$COUNT]}" - fi - - # Define long arguments. - if [[ $ARGSL == '' ]];then - ARGSL=${LONG[$COUNT]}${REQUIRED[$COUNT]} - else - ARGSL="${ARGSL},${LONG[$COUNT]}${REQUIRED[$COUNT]}" - fi - - # Increment counter. - COUNT=$(($COUNT + 1)) - - done - - # Parse arguments using getopt(1) command parser. - cli_doParseArguments - - # Reset positional parameters using output from (getopt) argument - # parser. - eval set -- "$ARGUMENTS" - - # Define action to take for each option passed. - while true; do - case "$1" in - - --filter ) - FLAG_FILTER="$2" - shift 2 - ;; - - --quiet ) - FLAG_QUIET="true" - shift 1 - ;; - - --answer ) - FLAG_ANSWER="$2" - shift 2 - ;; - - --dont-commit-changes ) - FLAG_DONT_COMMIT_CHANGES="true" - shift 1 - ;; - - * ) - break - ;; - esac - done - - # Redefine ARGUMENTS to use no-common arguments. Common arguments - # has been already parsed, so free specific functions from parsing - # them (there is no need to parse them twice). - if [[ ${COMMONS} != '' ]];then - - # Escape special regular expression characters that might be - # passed through common arguments like `--filter' in order to - # interpreted them literally. Otherwise they might be - # interpreted when they be stript out from default arguments. - COMMONS=$(echo ${COMMONS} | sed -r 's!(\(|\[|\{|\.|\+|\*)!\\\1!g') - - # Stript out common arguments from default arguments one by - # one to avoid order restrictions when removing them from - # string of default arguments. - for COMMON in ${COMMONS};do - ARGUMENTS_DEFAULT=$(echo ${ARGUMENTS_DEFAULT} | sed -r "s!${COMMON}!!g") - done - - fi - - # Use just default arguments. No common argument was passed. - eval set -- "${ARGUMENTS_DEFAULT}" - - # Redefine positional parameters stored inside ARGUMENTS variable. - cli_doParseArgumentsReDef "$@" - -} diff --git a/Scripts/Bash/Cli/Functions/cli_printMessage.sh b/Scripts/Bash/Cli/Functions/cli_printMessage.sh index 6bfd7c2..d2e9ff2 100755 --- a/Scripts/Bash/Cli/Functions/cli_printMessage.sh +++ b/Scripts/Bash/Cli/Functions/cli_printMessage.sh @@ -27,6 +27,11 @@ function cli_printMessage { + # Verify `--quiet' option. + if [[ "$FLAG_QUIET" == 'true' ]];then + return + fi + local MESSAGE="$1" local FORMAT="$2" @@ -144,35 +149,27 @@ function cli_printMessage { 'AsSeparatorLine' ) - if [[ "$FLAG_QUIET" == 'false' ]];then - - # Define separator width. - local MAX=70 - - # 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 - fi + # Output newline to end separator. + echo "" > /dev/stderr ;; 'AsNoTrailingNewLine' ) - if [[ "$FLAG_QUIET" == 'false' ]];then - printf "$MESSAGE" > /dev/stderr - fi + printf "$MESSAGE" > /dev/stderr ;; 'AsRegularLine' | * ) - if [[ "$FLAG_QUIET" == 'false' ]];then - echo "$MESSAGE" \ - | awk -f ${CLI_BASEDIR}/Styles/output_forTwoColumns.awk \ - > /dev/stderr - fi + echo "$MESSAGE" \ + | awk -f ${CLI_BASEDIR}/Styles/output_forTwoColumns.awk \ + > /dev/stderr ;; esac diff --git a/Scripts/Bash/Cli/Functions/cli_replaceTMarkers.sh b/Scripts/Bash/Cli/Functions/cli_replaceTMarkers.sh index af3adea..7024a39 100755 --- a/Scripts/Bash/Cli/Functions/cli_replaceTMarkers.sh +++ b/Scripts/Bash/Cli/Functions/cli_replaceTMarkers.sh @@ -74,11 +74,11 @@ function cli_replaceTMarkers { DST[4]="$(cli_getPathComponent "$OUTPUT" '--theme')" DST[5]="$(cli_getPathComponent "$OUTPUT" '--theme-name')" DST[6]="$(cli_getPathComponent "$OUTPUT" '--theme-release')" - DST[7]="$(cli_getPathComponent "$FLAG_RELEASE" '--release')" - DST[8]="$(cli_getPathComponent "$FLAG_RELEASE" '--release-major')" - DST[9]="$(cli_getPathComponent "$FLAG_RELEASE" '--release-minor')" + DST[7]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release')" + DST[8]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release-major')" + DST[9]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release-minor')" DST[10]="http://www.centos.org/=LOCALE_LL=" - DST[11]="$(cli_getPathComponent "$FLAG_ARCHITECTURE" '--architecture')" + DST[11]="$(cli_getPathComponent "$FLAG_BASEARCH" '--architecture')" DST[12]="http://wiki.centos.org/=LOCALE_LL=" DST[13]="http://lists.centos.org/=LOCALE_LL=" DST[14]="http://forums.centos.org/=LOCALE_LL="