Blame Scripts/Functions/Help/help.sh

4c79b5
#!/bin/bash
4c79b5
#
02d6e2
# help.sh -- This function standardizes the way documentation is
b0e781
# produced and maintained for "The CentOS Artwork Repository
b0e781
# Reference" documentation manual.
4c79b5
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
b0e781
# the Free Software Foundation; either version 2 of the License, or
b0e781
# (at 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=''
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
09b4e0
    # Define manual top level directory. This is where
09b4e0
    # language-specific documentation structures are stored in.
09b4e0
    MANUAL_TLDIR="$(cli_getRepoTLDir)/Manuals/RepoReference"
09b4e0
3ae895
    # Define file name (without extension) for documentation manual.
420e77
    MANUAL_NAME=$(cli_getRepoName "repository" -f)
1f6dd8
9fa13b
    # Define file extension used by documentation manual source files.
9fa13b
    MANUAL_EXTENSION='texinfo'
9fa13b
0c5b48
    # Define language information used by manual.
0c5b48
    MANUAL_LANG=$(cli_getCurrentLocale)
420e77
09b4e0
    # Define manual base directory. This is where the
09b4e0
    # language-specific document initialization file is stored in.
09b4e0
    MANUAL_BASEDIR="${MANUAL_TLDIR}/${MANUAL_LANG}"
23c4a7
23c4a7
    # Define base name for documentation manual files (without
23c4a7
    # extension). This is the main file name used to build output
23c4a7
    # related files (.info, .pdf, .xml, etc.).
23c4a7
    MANUAL_BASEFILE="${MANUAL_BASEDIR}/${MANUAL_NAME}"
23c4a7
23c4a7
    # Define chapter name of directory where repository documentation
23c4a7
    # entries will be stored in.
23c4a7
    MANUAL_CHAPTER_NAME=$(cli_getRepoName "Directories" -d)
23c4a7
23c4a7
    # Define absolute path to chapter directory where repository
23c4a7
    # documentation entries will be stored in.  At this point, we need
23c4a7
    # to take a desition about documentation design, in order to
23c4a7
    # answer the question: How do we assign chapters, sections and
23c4a7
    # subsections automatically, based on the repository structure?
23c4a7
    # and also, how such design could be adapted to changes in the
23c4a7
    # repository structure?
23c4a7
    #
23c4a7
    # One solution would be: represent the repository's directory
23c4a7
    # structure as sections inside a chapter named `Directories' or
23c4a7
    # something similar. Subsections and subsubsections will not have
23c4a7
    # their own files, they all will be written inside the same
23c4a7
    # section file that represents the repository documentation entry.
23c4a7
    MANUAL_CHAPTER_DIR=${MANUAL_BASEDIR}/${MANUAL_CHAPTER_NAME}
23c4a7
23c4a7
    # Define absolute path to backend template files.
09b4e0
    MANUAL_TEMPLATE=${FUNCDIR}/${FUNCDIRNAM}/Templates/${MANUAL_LANG}
23c4a7
23c4a7
    # Verify absolute path to backend template files. If the absolute
23c4a7
    # path doesn't exist, use the English language templates.
23c4a7
    if [[ ! -d $MANUAL_TEMPLATE ]];then
23c4a7
        MANUAL_TEMPLATE=${FUNCDIR}/${FUNCDIRNAM}/Templates/en_US
23c4a7
    fi
23c4a7
23c4a7
    # Create documentation structure, if it doesn't exist.
23c4a7
    ${FUNCNAM}_createStructure
23c4a7
0c5b48
    # Interpret option arguments passed through the command-line.
0c5b48
    ${FUNCNAM}_getOptions
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"
0c5b48
23c4a7
    # Syncronize changes between repository and working copy. At this
23c4a7
    # point, changes in the repository are merged in the working copy
23c4a7
    # and changes in the working copy committed up to repository.
23c4a7
    cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}
23c4a7
23c4a7
    # Execute backend functionalities. Notice that there are
23c4a7
    # functionalities that need more than one action value in order to
23c4a7
    # be executed (e.g.,  copying, and renaming), functionalities
23c4a7
    # that need just one action value to be executed (e.g.,
23c4a7
    # documentation reading and edition) and functionalities that
23c4a7
    # don't need action value at all (e.g., searching, reading and
23c4a7
    # updating output files). This way, the execution of backend
23c4a7
    # functionalities is splitted here.
23c4a7
    if [[ $ACTIONNAM =~ "${FUNCNAM}_(copy|rename|delete)Entry" ]];then
23c4a7
23c4a7
        # Execute backend action names that may need to use more than
23c4a7
        # one action value.
23c4a7
        ${ACTIONNAM} $@
23c4a7
23c4a7
    elif [[ $ACTIONNAM =~ "${FUNCNAM}_(search(Index|Node)|updateOutputFiles)" ]];then
23c4a7
23c4a7
        # Execute backend action names that might not need any action
23c4a7
        # value as reference to do their work.
23c4a7
        $ACTIONNAM $@
23c4a7
23c4a7
        # Backend action names that don't need to use any action value
23c4a7
        # as reference to do their work are of one-pass only. They are
23c4a7
        # executed and then the script execution is finished.
23c4a7
        exit
23c4a7
e5750b
    else
23c4a7
23c4a7
        # Execute backend action names that use one action value, only.
23c4a7
        for ACTIONVAL in $@;do
23c4a7
        
23c4a7
            # Define documentation entry.
23c4a7
            MANUAL_ENTRY=$(${FUNCNAM}_getEntry $ACTIONVAL)
23c4a7
23c4a7
            # Execute backend action names that may need to use more
23c4a7
            # than one action value.
72b768
            $ACTIONNAM
23c4a7
23c4a7
        done
23c4a7
e5750b
    fi
c145a8
23c4a7
    # Commit changes from working copy to central repository only.  At
23c4a7
    # this point, changes in the repository are not merged in the
23c4a7
    # working copy, but chages in the working copy do are committed up
23c4a7
    # to repository.
23c4a7
    cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}
23c4a7
23c4a7
    # Rebuild output files to propagate recent changes.
23c4a7
    ${FUNCNAM}_updateOutputFiles
23c4a7
23c4a7
}