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
3ae895
    # Define file name (without extension) for documentation manual.
69150d
    MANUAL_NAME=repository
1f6dd8
deaa54
    # Interpret option arguments passed through the command-line.
fa1906
    ${FUNCNAM}_getOptions
c145a8
fa1906
    # Initialize backend functions.  There is no need to load all
fa1906
    # backend-specific functions when we can use just one backend
fa1906
    # among many. Keep the cli_getFunctions function calling after all
fa1906
    # variables and arguments definitions.
fa1906
    cli_getFunctions "${FUNCDIR}/${FUNCDIRNAM}" "${FLAG_BACKEND}"
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"
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
        ACTIONVALS[((++${#ACTIONVALS[*]}))]="$ACTIONVAL"
5ec287
    done
deaa54
 
5ec287
    # Enforce conditions against remaining non-option arguments before
5ec287
    # processing them.
5ec287
    if [[ ${ACTIONNAM} == ${FUNCNAM}_copyEntry ]];then
5ec287
5ec287
        # When a documentation entry is copied, we need to determine
5ec287
        # what location to use as target.  To solve this, the last
5ec287
        # argument passed to centos-art script is taken as target
5ec287
        # location. All other arguments previously defined are
5ec287
        # considered source locations. Notice that more than one
5ec287
        # source location can be specified, but just one target
5ec287
        # location can exist.
5ec287
        local -a ENTRY_SRC
5ec287
        local ENTRY_DST=''
5ec287
        local COUNT=0
5ec287
5ec287
        # Define list of source locations using remaining arguments.
5ec287
        while [[ ${COUNT} -lt $((${#ACTIONVALS[*]} - 1)) ]];do
5ec287
            ENTRY_SRC[((++${#ENTRY_SRC[*]}))]=${ACTIONVALS[$COUNT]}
5ec287
            COUNT=$(($COUNT + 1))
5ec287
        done
5ec287
5ec287
        # Define target location.
5ec287
        ENTRY_DST=$(cli_checkRepoDirTarget "${ACTIONVALS[((${#ACTIONVALS[*]} - 1))]}")
5ec287
5ec287
        # Define target documentation entry.
5ec287
        ENTRY_DST=$(help_getEntry "$ENTRY_DST")
5ec287
5ec287
        # Redefine arguments to store source locations only.
5ec287
        ARGUMENTS=${ENTRY_SRC[@]}
5ec287
5ec287
    elif [[ ${ACTIONNAM} == ${FUNCNAM}_renameEntry ]];then
5ec287
5ec287
        # When documentation entry is renamed, we need to restrict the
5ec287
        # number of arguments to two arguments only.  More than two
5ec287
        # arguments are useless since the renaming action works with
5ec287
        # two arguments only. This is, the source location and the
5ec287
        # target location.
5ec287
        local ENTRY_SRC=''
5ec287
        local ENTRY_DST=''
5ec287
5ec287
        # Verify number of arguments passed to centos-art.sh script.
5ec287
        if [[ ${#ACTIONVALS[*]} -gt 2 ]];then
18be6e
            cli_printMessage "`gettext "Only two arguments are accepted."`" --as-error-line
5ec287
        elif [[ ${#ACTIONVALS[*]} -lt 2 ]];then
18be6e
            cli_printMessage "`gettext "Two arguments are required."`" --as-error-line
5ec287
        fi
5ec287
5ec287
        # Define source location. 
5ec287
        ENTRY_SRC=${ACTIONVALS[0]}
5ec287
5ec287
        # Define target location.
5ec287
        ENTRY_DST=$(cli_checkRepoDirTarget "${ACTIONVALS[1]}")
5ec287
5ec287
        # Define target documentation entry.
5ec287
        ENTRY_DST=$(help_getEntry "${ACTIONVALS[1]}")
5ec287
5ec287
        # Redefine arguments to store source locations only.
5ec287
        ARGUMENTS=$ENTRY_SRC
5ec287
5ec287
    else
5ec287
5ec287
        # Redefine arguments to store all arguments.
5ec287
        ARGUMENTS=$@
5ec287
5ec287
    fi
5ec287
f11f54
    # Verify non-option arguments.  When non-option arguments are
f11f54
    # passed to `centos-art.sh' script, use the base manual directory
f11f54
    # structure. This make possible that option like `--search' and
f11f54
    # `--update' can be executed without passing any `path/to/dir'
f11f54
    # information in the command line.
f11f54
    if [[ $ARGUMENTS == '' ]];then
f11f54
        ARGUMENTS=${MANUAL_BASEDIR}
f11f54
    fi
f11f54
6cda26
    # Define action value. As convenction, we use non-option arguments
6cda26
    # to define the action value (ACTIONVAL) variable.
5ec287
    for ACTIONVAL in $ARGUMENTS;do
c145a8
c145a8
        # Check action value passed through the command-line using
c145a8
        # source directory definition as reference.
c145a8
        cli_checkRepoDirSource
deaa54
    
deaa54
        # Define manuals base directory. This is the place where
deaa54
        # documentation manuals base directory structures are stored
deaa54
        # and organized in.
fa1906
        MANUAL_BASEDIR="$(cli_getRepoTLDir)/Manuals/$(cli_getRepoName ${FLAG_BACKEND} -d)"
deaa54
deaa54
        # Define base name for documentation manual files (without
fa1906
        # extension). This is the main file name used to build output
deaa54
        # related files (.info, .pdf, .xml, etc.).
deaa54
        MANUAL_BASEFILE="${MANUAL_BASEDIR}/${MANUAL_NAME}"
c145a8
d212c9
        # Define function configuration directory. The function
d212c9
        # configuration directory is used to store functionality's
d212c9
        # related files.
d212c9
        MANUAL_TEMPLATE=${FUNCDIR}/${FUNCDIRNAM}/Templates
d212c9
c145a8
        # Define documentation entry.
deaa54
        ENTRY=$(${FUNCNAM}_getEntry)
c145a8
c145a8
        # Define documentation entry directory. This is the directory
fa1906
        # where the entry file is stored.  When the file extension be
fa1906
        # removed, consider that several backends could be used.
fa1906
        ENTRY_DIR=$(dirname ${ENTRY} | sed -r "s/\.${FLAG_BACKEND}$//")
c145a8
c145a8
        # Define documentation entry file (without extension).
fa1906
        ENTRY_FILE=$(basename ${ENTRY} | sed -r "s/\.${FLAG_BACKEND}$//")
c145a8
c145a8
        # Define directory to store documentation entries.  At this
c145a8
        # point, we need to take a desition about documentation
c145a8
        # design, in order to answer the question: How do we assign
c145a8
        # chapters, sections and subsections automatically, based on
c145a8
        # the repository structure?  and also, how such design could
c145a8
        # be adapted to changes in the repository structure?
c145a8
        #
c145a8
        # One solution would be: represent the repository's directory
0b20e8
        # structure as sections inside a chapter named `Directories'
0b20e8
        # or something similar. Subsections and subsubsections will
0b20e8
        # not have their own files, they all will be written inside
0b20e8
        # the same section file that represents the repository
0b20e8
        # documentation entry.
a664d5
        MANUAL_CHAPTER_DIR=$(echo $ENTRY | cut -d / -f-8)
c145a8
c145a8
        # Define chapter name for the documentation entry we are
c145a8
        # working with.
c145a8
        MANUAL_CHAPTER_NAME=$(basename "$MANUAL_CHAPTER_DIR")
c145a8
c145a8
        # Syncronize changes between repository and working copy. At
c145a8
        # this point, changes in the repository are merged in the
c145a8
        # working copy and changes in the working copy committed up to
c145a8
        # repository.
0b20e8
        cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}
c145a8
fa1906
        # Verify action name against the file ought to be initialized
fa1906
        # from. If the file exists it is very sure that it has been
fa1906
        # already initialized, so execute the action name. Otherwise,
fa1906
        # if the file doesn't exist, print an error message. It is not
fa1906
        # possible to execute a function which definition hasn't been
fa1906
        # initialized.
116f45
        if [[ -f ${FUNCDIR}/${FUNCDIRNAM}/${ACTIONNAM}.sh  ]];then
c145a8
            eval $ACTIONNAM
c145a8
        else
18be6e
            cli_printMessage "`gettext "A valid action is required."`" --as-error-line
c145a8
        fi
638bf8
c145a8
        # Commit changes from working copy to central repository only.
c145a8
        # At this point, changes in the repository are not merged in
c145a8
        # the working copy, but chages in the working copy do are
c145a8
        # committed up to repository.
0b20e8
        cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}
4c79b5
c145a8
    done
3ae895
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
}