Blame Scripts/Functions/Help/help.sh

4c79b5
#!/bin/bash
4c79b5
#
02d6e2
# help.sh -- This function standardizes the way documentation is
02d6e2
# produced and maintain inside the working copy of CentOS Artwork
02d6e2
# Repository.
4c79b5
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
    
0211a4
function help {
2bd980
c145a8
    local ACTIONNAM=''
c145a8
    local ACTIONVAL=''
5ec287
    local -a ACTIONVALS
c145a8
1b527b
    # Initialize the search option. The search option (`--search')
1b527b
    # specifies the pattern used inside info files when an index
1b527b
    # search is perform.
1b527b
    FLAG_SEARCH=""
1b527b
fa1906
    # Initialize the backend option. The backend option (`--backend')
fa1906
    # specifies the backend used to manipulate the repository
deaa54
    # documentation manual.
fa1906
    FLAG_BACKEND="docbook"
5285d6
e5750b
    # Interpret option arguments passed through the command-line.
e5750b
    ${FUNCNAM}_getOptions
e5750b
e5750b
    # Define manuals base directory. This is the place where
e5750b
    # documentation manuals base directory structures are stored and
e5750b
    # organized in.
e5750b
    MANUAL_BASEDIR="$(cli_getRepoTLDir)/Manuals/$(cli_getRepoName ${FLAG_BACKEND} -d)"
e5750b
3ae895
    # Define file name (without extension) for documentation manual.
69150d
    MANUAL_NAME=repository
1f6dd8
e5750b
    # Define base name for documentation manual files (without
e5750b
    # extension). This is the main file name used to build output
e5750b
    # related files (.info, .pdf, .xml, etc.).
e5750b
    MANUAL_BASEFILE="${MANUAL_BASEDIR}/${MANUAL_NAME}"
c145a8
e5750b
    # Define function configuration directory. The function
e5750b
    # configuration directory is used to store functionality's related
e5750b
    # files.
e5750b
    MANUAL_TEMPLATE=${FUNCDIR}/${FUNCDIRNAM}/Templates
116f45
c145a8
    # Redefine positional parameters using ARGUMENTS. At this point,
c145a8
    # option arguments have been removed from ARGUMENTS variable and
c145a8
    # only non-option arguments remain in it. 
c145a8
    eval set -- "$ARGUMENTS"
e5750b
 
e5750b
    # Verify and initialize backend functions.  There is no need to
e5750b
    # load all backend-specific functions when we can use just one
e5750b
    # backend among many. Keep the cli_getFunctions function calling
e5750b
    # after all variables and arguments definitions.
e5750b
    if [[ ${FLAG_BACKEND} =~ '^texinfo$' ]];then
e5750b
        cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}" 'texinfo'
e5750b
    elif [[ ${FLAG_BACKEND} =~ '^docbook$' ]];then
e5750b
        cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}" 'docbook'
e5750b
    else
e5750b
        cli_printMessage "`gettext "The backend provided is not supported."`" --as-error-line
e5750b
    fi
c145a8
5ec287
    # Store remaining arguments into an array. This way it is possible
5ec287
    # to find out which is the last argument in the list.  When
5ec287
    # copying files inside the repository, the last argument in the
5ec287
    # list is considered the target location and all other arguments
02d6e2
    # are considered the source locations. Similary, when renaming
5ec287
    # files, only two arguments can be passed.
5ec287
    for ACTIONVAL in "$@";do
5ec287
e5750b
        # Sanitate action value.
e5750b
        cli_checkRepoDirSource
5ec287
e5750b
        # Assign sanitated action vlue.
e5750b
        ACTIONVALS[((++${#ACTIONVALS[*]}))]=$ACTIONVAL
5ec287
e5750b
    done
5ec287
e5750b
    # Execute backend functionalities. Notice that there are
e5750b
    # functionalities that need more than one action value in order to
e5750b
    # be executed (eg.  copying, and renaming) and functionalities
e5750b
    # that need just one action value to be executed (e.g.,
e5750b
    # documentation reading and edition). This way, the execution of
e5750b
    # backend functionalities is splitted here.
e5750b
    if [[ $ACTIONNAM =~ "${FLAG_BACKEND}_(copy|rename|delete)Entry" ]];then
5ec287
e5750b
        # Execute backend action names that may need to use more than
e5750b
        # one action value.
e5750b
        ${ACTIONNAM}
5ec287
5ec287
    else
5ec287
e5750b
        # Execute backend action names that use one action value, only.
e5750b
        for ACTIONVAL in ${ACTIONVALS[@]};do
e5750b
            ${FLAG_BACKEND}
e5750b
        done
5ec287
f11f54
    fi
f11f54
3ae895
    # Perform language-specific actions when the current language is
3ae895
    # other but English language.
3ae895
    if [[ ! $(cli_getCurrentLocale) =~ '^en' ]];then
3ae895
3ae895
        # Update translatable strings in related portable objects.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh locale --update ${MANUAL_BASEFILE}.xhtml --dont-commit-changes
3ae895
3ae895
        # Update translatable strings in related portable objects.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh locale --edit ${MANUAL_BASEFILE}.xhtml
3ae895
3ae895
        # Print separator.
3ae895
        cli_printMessage '-' --as-separator-line
3ae895
3ae895
        # Print action message.
3ae895
        cli_printMessage "${MANUAL_BASEFILE}.xhtml/$(cli_getCurrentLocale)" '--as-updating-line'
3ae895
3ae895
        # Render translated versions of the XHTML output files,
3ae895
        # supressing the rendition output.
3ae895
        eval ${CLI_BASEDIR}/${CLI_PROGRAM}.sh render ${MANUAL_BASEFILE}.xhtml --dont-commit-changes --quiet
3ae895
3ae895
    fi
3ae895
4c79b5
}