Blame Scripts/Bash/Functions/Manual/manual_getActions.sh

4c79b5
#!/bin/bash
4c79b5
#
2bd980
# manual_getActions.sh -- This function interpretes arguments passed
2bd980
# to `manual' functionality and calls actions accordingly.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# 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
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4de5d4
function manual_getActions {
4c79b5
2bd980
    # Define short options we want to support.
2bd980
    local ARGSS=""
2bd980
2bd980
    # Define long options we want to support.
5285d6
    local ARGSL="read:,search:,edit:,delete:,update:,copy:,to:"
2bd980
2bd980
    # Parse arguments using getopt(1) command parser.
2bd980
    cli_doParseArguments
2bd980
2bd980
    # Reset positional parameters using output from (getopt) argument
2bd980
    # parser.
2bd980
    eval set -- "$ARGUMENTS"
2bd980
2bd980
    # Define action to take for each option passed.
2bd980
    while true; do
2bd980
        case "$1" in
2bd980
638bf8
            --read )
2bd980
                ACTIONVAL="$2"
638bf8
                ACTIONNAM="${FUNCNAM}_searchNode"
638bf8
                shift 2
638bf8
                ;;
638bf8
638bf8
            --search )
638bf8
                ACTIONVAL="$2"
2bd980
                ACTIONNAM="${FUNCNAM}_searchIndex"
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
2bd980
            --edit )
2bd980
                ACTIONVAL="$2"
2bd980
                ACTIONNAM="${FUNCNAM}_editEntry"
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
2bd980
            --delete )
2bd980
                ACTIONVAL="$2"
742c46
                ACTIONNAM="${FUNCNAM}_deleteEntry"
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
638bf8
            --update )
5285d6
                ACTIONVAL="$2"
5285d6
                ACTIONNAM="${FUNCNAM}_updateOutputFiles"
5285d6
                shift 2
2bd980
                ;;
4c79b5
    
638bf8
            --copy )
2bd980
                ACTIONVAL="$2"
638bf8
                ACTIONNAM="${FUNCNAM}_copyEntry"
638bf8
                shift 2
2bd980
                ;;
2bd980
638bf8
            --to )
638bf8
                FLAG_TO="$2"
638bf8
                shift 2
638bf8
                ;;
2bd980
2bd980
            * )
638bf8
                # Break options loop.
2bd980
                break
2bd980
        esac
2bd980
    done
2bd980
638bf8
    # Check action value passed through the command-line using source
638bf8
    # directory definition as reference.
638bf8
    cli_checkRepoDirSource
2bd980
2bd980
    # Define documentation entry.
2bd980
    ENTRY=$(manual_getEntry)
2bd980
5285d6
    # Define directory for documentation manual. This is the place the
5285d6
    # specific documentation manual we are working with is stored in.
5285d6
    MANUAL_DIR=$(echo $ENTRY | cut -d / -f-7)
5285d6
5285d6
    # Define directory to store documentation entries.  At this point,
5285d6
    # we need to take a desition about documentation design, in order
5285d6
    # to answer the question: How do we assign chapters, sections and
5285d6
    # subsections automatically, based on the repository structure?
5285d6
    # and also, how such design could be adapted to changes in the
5285d6
    # repository structure?
2bd980
    #
5285d6
    # One solution would be: represent the repository's first level
5285d6
    # structure in three chapters only (i.e., trunk, branches, and
5285d6
    # tags) and handle everything else inside them as sections. Sub
2bd980
    # and subsub section will not have their own files, they will be
2bd980
    # written inside section files instead.
5285d6
    MANUAL_DIR_CHAPTER=$(echo $ENTRY | cut -d / -f-8)
5285d6
5285d6
    # Define chapter name for the documentation entry we are working
5285d6
    # with.
5285d6
    MANUAL_CHA_NAME=$(basename "$MANUAL_DIR_CHAPTER")
2bd980
5285d6
    # Define base name for documentation manual files. This is the
5285d6
    # main file name used to build texinfo related files (.info, .pdf,
5285d6
    # .xml, etc.).
5285d6
    MANUAL_BASEFILE=$(echo $ENTRY | cut -d / -f-7)
5285d6
    MANUAL_BASEFILE=${MANUAL_BASEFILE}/$(cli_getRepoName "${MANUAL_BASEFILE}" 'f')
2bd980
b88dec
    # Syncronize changes between the working copy and the central
b88dec
    # repository to bring down changes.
5285d6
    cli_commitRepoChanges ${MANUAL_DIR}
b88dec
2bd980
    # Execute action name.
2bd980
    if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then
2bd980
        eval $ACTIONNAM
2bd980
    else
2bd980
        cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine'
2bd980
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
2bd980
    fi
4c79b5
b88dec
    # Syncronize changes between the working copy and the central
b88dec
    # repository to commit up changes.
5285d6
    cli_commitRepoChanges ${MANUAL_DIR}
b88dec
4c79b5
}