Blame Scripts/Functions/Help/help_getEntries.sh

e82789
#!/bin/bash
e82789
#
e82789
# help_getEntries.sh -- This function interpretes non-option
e82789
# arguments passed to `help' functionality through the command-line
e82789
# and redefines array variables related to documentation entries.
e82789
#
e82789
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
e82789
#
e82789
# This program is free software; you can redistribute it and/or modify
e82789
# it under the terms of the GNU General Public License as published by
e82789
# the Free Software Foundation; either version 2 of the License, or (at
e82789
# your option) any later version.
e82789
#
e82789
# This program is distributed in the hope that it will be useful, but
e82789
# WITHOUT ANY WARRANTY; without even the implied warranty of
e82789
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e82789
# General Public License for more details.
e82789
#
e82789
# You should have received a copy of the GNU General Public License
e82789
# along with this program; if not, write to the Free Software
e82789
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
e82789
#
e82789
# ----------------------------------------------------------------------
e82789
# $Id$
e82789
# ----------------------------------------------------------------------
e82789
e82789
function help_getEntries {
e82789
e82789
    local DOCENTRY=''
e82789
e82789
    # Redefine positional parameters using ARGUMENTS. At this point,
e82789
    # option arguments have been removed from ARGUMENTS variable and
e82789
    # only non-option arguments remain in it. 
e82789
    eval set -- "$ARGUMENTS"
e82789
edaa9d
    if [[ $@ == '' ]];then
e82789
edaa9d
        # Define default documentation entry. This happen when
edaa9d
        # non-option arguments aren't provided to centos-art.sh
edaa9d
        # script.  Default documentation entry defined here points to
edaa9d
        # manual's main definition file, so only the manual's self
edaa9d
        # name and manual's directory name need to be defined here.
ccf995
        MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
ccf995
        MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]='Tcar-fs'
edaa9d
        MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
e82789
edaa9d
    else
e82789
edaa9d
        # Retrive documentation entries passed to centos-art.sh script
edaa9d
        # as non-option arguments and store them in array variables in
edaa9d
        # order to describe their parts (e.g., manual name, chapter
edaa9d
        # name and section name) that way.  Documentation entries
aee706
        # passed as non-opiton arguments must be written in either
aee706
        # `MANUAL:CHAPTER:SECTION' or `path/to/dir' formats in order
aee706
        # to be processed correctly here. Empty spaces are not
aee706
        # permitted. To separate words, use the minus sign (e.g.,
aee706
        # hello-world) or cammel case (e.g., HelloWorld).
edaa9d
        for DOCENTRY in $@;do
e82789
aee706
            if [[ $DOCENTRY =~ '^([[:alnum:]-]+:){1,3}' ]];then
e82789
aee706
                # When `MANUAL:CHAPTER:SECTION' is used as format to
aee706
                # documentation entry, you can specify the manual,
aee706
                # chapter and section where documentation actions will
aee706
                # take place on.
edaa9d
aee706
                # Manual self name.
aee706
                MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
aee706
                    $(echo "$DOCENTRY" | gawk 'BEGIN{ FS=":" } { print $1 }') -f \
aee706
                    | tr '[:upper:]' '[:lower:]')
edaa9d
aee706
                # Manual self directory name.
aee706
                MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
aee706
                    $(echo "$DOCENTRY" | gawk 'BEGIN{ FS=":" } { print $1 }') -d )
aee706
aee706
                # Manual chapter name.
aee706
                MANUAL_CHAN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
aee706
                    $(echo "$DOCENTRY" | gawk 'BEGIN{ FS=":" } { print $2 }') -d )
aee706
aee706
                # Manual section name.
aee706
                MANUAL_SECN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
aee706
                    $(echo "$DOCENTRY" | gawk 'BEGIN{ FS=":" } { print $3 }') -f )
aee706
aee706
            elif [[ $DOCENTRY =~ '^(trunk|branches|tags)' ]];then
aee706
aee706
                # When `path/to/dir' is used as format to
aee706
                # documentation entry, you cannot specify the manual
aee706
                # chapter or section where documentation actions will
aee706
                # take place on. Instead, they are predefined for you
aee706
                # here. Use this format to document directories inside
aee706
                # your working copy.
aee706
aee706
                # Manual self name.
aee706
                MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
aee706
aee706
                # Manual self directory name.
aee706
                MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]='Tcar-fs'
aee706
aee706
                # Manual chapter name.
aee706
                MANUAL_CHAN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
5158b4
                    $(echo "$DOCENTRY" | gawk 'BEGIN { FS="/" }; { if ( NF >= 1 ) print $1 }' ) -d )
aee706
aee706
                # Manual section name.
aee706
                MANUAL_SECN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
5158b4
                    $(echo "$DOCENTRY" | gawk 'BEGIN { FS="/" }; { if ( NF >= 2 ) print $0 }' \
5158b4
                    | cut -d/ -f2- | tr '/' '-') -f )
aee706
aee706
            else
aee706
                cli_printMessage "`gettext "The documentation entry provided isn't supported."`" --as-error-line
aee706
            fi
edaa9d
edaa9d
            # Increment counting of non-option arguments.
edaa9d
            MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
e82789
edaa9d
        done
e82789
edaa9d
    fi
e82789
}