From 5ec287ef15432ff00f13c541d2eabeb423803ac6 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Apr 01 2011 15:57:15 +0000 Subject: Update help.sh. --- diff --git a/Scripts/Functions/Help/help.sh b/Scripts/Functions/Help/help.sh index a19e251..f7ccc75 100755 --- a/Scripts/Functions/Help/help.sh +++ b/Scripts/Functions/Help/help.sh @@ -28,6 +28,7 @@ function help { local ACTIONNAM='' local ACTIONVAL='' + local -a ACTIONVALS # Define manuals base directory. This is the place where # documentation manuals base directory structures are stored and @@ -43,14 +44,92 @@ function help { # related files (.info, .pdf, .xml, etc.). MANUAL_BASEFILE="${MANUAL_BASEDIR}/${MANUAL_NAME}" - # Interpret arguments and options passed through command-line. - help_getArguments + # Interpret option arguments passed through command-line. + help_getOptions # 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" + # Store remaining arguments into an array. This way it is possible + # to find out which is the last argument in the list. When + # copying files inside the repository, the last argument in the + # list is considered the target location and all other arguments + # are considered source the locations. Similary, when renaming + # files, only two arguments can be passed. + for ACTIONVAL in "$@";do + ACTIONVALS[((++${#ACTIONVALS[*]}))]="$ACTIONVAL" + done + + # Enforce conditions against remaining non-option arguments before + # processing them. + if [[ ${ACTIONNAM} == ${FUNCNAM}_copyEntry ]];then + + # When a documentation entry is copied, we need to determine + # what location to use as target. To solve this, the last + # argument passed to centos-art script is taken as target + # location. All other arguments previously defined are + # considered source locations. Notice that more than one + # source location can be specified, but just one target + # location can exist. + local -a ENTRY_SRC + local ENTRY_DST='' + local COUNT=0 + + # Define list of source locations using remaining arguments. + while [[ ${COUNT} -lt $((${#ACTIONVALS[*]} - 1)) ]];do + ENTRY_SRC[((++${#ENTRY_SRC[*]}))]=${ACTIONVALS[$COUNT]} + COUNT=$(($COUNT + 1)) + done + + # Define target location. + ENTRY_DST=$(cli_checkRepoDirTarget "${ACTIONVALS[((${#ACTIONVALS[*]} - 1))]}") + + # Define target documentation entry. + ENTRY_DST=$(help_getEntry "$ENTRY_DST") + + # Redefine arguments to store source locations only. + ARGUMENTS=${ENTRY_SRC[@]} + + elif [[ ${ACTIONNAM} == ${FUNCNAM}_renameEntry ]];then + + # When documentation entry is renamed, we need to restrict the + # number of arguments to two arguments only. More than two + # arguments are useless since the renaming action works with + # two arguments only. This is, the source location and the + # target location. + local ENTRY_SRC='' + local ENTRY_DST='' + + # Verify number of arguments passed to centos-art.sh script. + if [[ ${#ACTIONVALS[*]} -gt 2 ]];then + cli_printMessage "`gettext "Only two arguments are accepted."`" 'AsErrorLine' + cli_printMessage "${FUNCDIRNAME}" 'AsToKnowMoreLine' + elif [[ ${#ACTIONVALS[*]} -lt 2 ]];then + cli_printMessage "`gettext "Two arguments are required."`" 'AsErrorLine' + cli_printMessage "${FUNCDIRNAME}" 'AsToKnowMoreLine' + fi + + # Define source location. + ENTRY_SRC=${ACTIONVALS[0]} + + # Define target location. + ENTRY_DST=$(cli_checkRepoDirTarget "${ACTIONVALS[1]}") + + # Define target documentation entry. + ENTRY_DST=$(help_getEntry "${ACTIONVALS[1]}") + + # Redefine arguments to store source locations only. + ARGUMENTS=$ENTRY_SRC + + else + + # Redefine arguments to store all arguments. + ARGUMENTS=$@ + + fi + # Define action name. It does matter what option be passed to # centos-art, there are many different actions to perform based on # the option passed (e.g., `--edit', `--read', `--search', etc.). @@ -59,7 +138,7 @@ function help { # Define action value. As convenction, we use non-option arguments # to define the action value (ACTIONVAL) variable. - for ACTIONVAL in "$@";do + for ACTIONVAL in $ARGUMENTS;do # Check action value passed through the command-line using # source directory definition as reference. @@ -87,7 +166,7 @@ function help { # something similar. Subsections and subsubsections will not # have their own files, they all will be written inside the # same section file that represents the repository directory. - MANUAL_CHAPTER_DIR=$(echo $ENTRY | cut -d / -f-7) + MANUAL_CHAPTER_DIR=$(echo $ENTRY | cut -d / -f-8) # Define chapter name for the documentation entry we are # working with.