Blame Automation/Modules/Help/help_getEntries.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# help_getEntries.sh -- This function interpretes non-option
Alain Reguera Delgado 8f60cb
# arguments passed to `help' functionality through the command-line
Alain Reguera Delgado 8f60cb
# and redefines array variables related to documentation entries.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function help_getEntries {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize manual's documentation entry as an empty value local
Alain Reguera Delgado 8f60cb
    # to this function.
Alain Reguera Delgado 8f60cb
    local MANUAL_DOCENTRY=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Redefine positional parameters using ARGUMENTS. At this point,
Alain Reguera Delgado 8f60cb
    # option arguments have been removed from ARGUMENTS variable and
Alain Reguera Delgado 8f60cb
    # only non-option arguments remain in it. 
Alain Reguera Delgado 8f60cb
    eval set -- "$ARGUMENTS"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Retrive documentation entries passed to `centos-art.sh' script
Alain Reguera Delgado 8f60cb
    # as non-option arguments and store them in array variables in
Alain Reguera Delgado 8f60cb
    # order to describe their parts (e.g., manual name, chapter name
Alain Reguera Delgado 8f60cb
    # and section name) that way.  Documentation entries passed as
Alain Reguera Delgado 8f60cb
    # non-opiton arguments must be written either in
Alain Reguera Delgado 8f60cb
    # `MANUAL:PART:CHAPTER:SECTION' or `path/to/dir' formats in order
Alain Reguera Delgado 8f60cb
    # to be processed correctly here. Empty spaces are not permitted.
Alain Reguera Delgado 8f60cb
    # To separate words, use the minus sign (e.g., hello-world) or
Alain Reguera Delgado 8f60cb
    # cammel case (e.g., HelloWorld).
Alain Reguera Delgado 8f60cb
    for MANUAL_DOCENTRY in $@;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        if [[ ${MANUAL_DOCENTRY} =~ '^[[:alpha:]][[:alnum:]-]+:([[:alnum:]-]*:){2}[[:alnum:]/]*' ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # When `MANUAL:PART:CHAPTER:SECTION' is used as format to
Alain Reguera Delgado 8f60cb
            # documentation entry, you can specify the manual, chapter
Alain Reguera Delgado 8f60cb
            # and section where documentation actions will take place
Alain Reguera Delgado 8f60cb
            # on.
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual self name.
Alain Reguera Delgado 8f60cb
            MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $1 }') -f \
Alain Reguera Delgado 8f60cb
                | tr '[:upper:]' '[:lower:]')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual self directory name.
Alain Reguera Delgado 8f60cb
            MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $1 }') -d )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual part name.
Alain Reguera Delgado 8f60cb
            MANUAL_PART[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $2 }') -d )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual chapter name.
Alain Reguera Delgado 8f60cb
            MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $3 }') -d )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual section name.
Alain Reguera Delgado 8f60cb
            MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $4 }' | tr '/' '-') -f )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        elif [[ ${MANUAL_DOCENTRY} =~ "^(trunk|branches|tags)?(/)?($(ls ${TCAR_WORKDIR} \
Alain Reguera Delgado 8f60cb
            | tr '[[:space:]]' '|' | sed 's/|$//'))" ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # When we use the `path/to/dir' as format to reach
Alain Reguera Delgado 8f60cb
            # documentation entries, you cannot specify the manual
Alain Reguera Delgado 8f60cb
            # chapter or section where documentation actions will take
Alain Reguera Delgado 8f60cb
            # place on. Instead, they are predefined for you here. Use
Alain Reguera Delgado 8f60cb
            # this format to quickly document directories inside your
Alain Reguera Delgado 8f60cb
            # working copy.
Alain Reguera Delgado 8f60cb
            #
Alain Reguera Delgado 8f60cb
            # When we use the `path/to/dir' format to reach
Alain Reguera Delgado 8f60cb
            # documentation entries, there is a distinction between
Alain Reguera Delgado 8f60cb
            # Subversion and Git version control system we need to be
Alain Reguera Delgado 8f60cb
            # aware of.  This is the directory structure layout used
Alain Reguera Delgado 8f60cb
            # in the repository.  In Subversion, we use a trunk/,
Alain Reguera Delgado 8f60cb
            # branches/, tags/ layout as first level in the repository
Alain Reguera Delgado 8f60cb
            # directory structure but, in Git, we don't need such
Alain Reguera Delgado 8f60cb
            # special layout in the repository's first directory
Alain Reguera Delgado 8f60cb
            # level. The script must be able to understand both
Alain Reguera Delgado 8f60cb
            # directory structures.
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual's self name.
Alain Reguera Delgado 8f60cb
            MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual's self directory name.
Alain Reguera Delgado 8f60cb
            MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                ${MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]} -d)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual's chapter name.
Alain Reguera Delgado 8f60cb
            MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 1 ) print $1 }' ) -d )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Manual's section name.
Alain Reguera Delgado 8f60cb
            MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
Alain Reguera Delgado 8f60cb
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 2 ) print $0 }' \
Alain Reguera Delgado 8f60cb
                | cut -d/ -f2- | tr '/' '-') -f )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            cli_printMessage "`gettext "The documentation entry provided isn't supported."`" --as-error-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment counting of non-option arguments.
Alain Reguera Delgado 8f60cb
        MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}