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
    # Verify language layout.
4de5d4
    manual_checkLanguageLayout
4c79b5
2bd980
    # Define short options we want to support.
2bd980
    local ARGSS=""
2bd980
2bd980
    # Define long options we want to support.
638bf8
    local ARGSL="read:,search:,edit:,delete:,update,copy:,to:,quiet,yes"
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
2bd980
                # Define action value passed through the command-line.
2bd980
                ACTIONVAL="$2"
2bd980
638bf8
                # Define action name using action value as reference.
638bf8
                ACTIONNAM="${FUNCNAM}_searchNode"
638bf8
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
638bf8
                ;;
638bf8
638bf8
            --search )
638bf8
638bf8
                # Define action value passed through the command-line.
638bf8
                ACTIONVAL="$2"
2bd980
2bd980
                # Define action name using action value as reference.
2bd980
                ACTIONNAM="${FUNCNAM}_searchIndex"
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
2bd980
            --edit )
2bd980
2bd980
                # Define action value passed through the command-line.
2bd980
                ACTIONVAL="$2"
2bd980
2bd980
                # Define action name using action value as reference.
2bd980
                ACTIONNAM="${FUNCNAM}_editEntry"
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
2bd980
            --delete )
2bd980
2bd980
                # Define action value passed through the command-line.
2bd980
                ACTIONVAL="$2"
2bd980
2bd980
                # Define action name.
742c46
                ACTIONNAM="${FUNCNAM}_deleteEntry"
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
2bd980
                ;;
4c79b5
    
638bf8
            --update )
2bd980
2bd980
                # Execute action name. There is no need of action
2bd980
                # value here, so let's execute the action right now.
2bd980
                manual_updateOutputFiles
2bd980
60546b
                # End script execution flow. There is nothing else to
60546b
                # do after updating documentation output.
60546b
                exit
2bd980
                ;;
4c79b5
    
638bf8
            --copy )
2bd980
2bd980
                # Define action value passed through the command-line.
2bd980
                ACTIONVAL="$2"
2bd980
2bd980
                # Define action name using action value as reference.
638bf8
                ACTIONNAM="${FUNCNAM}_copyEntry"
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
2bd980
                ;;
2bd980
638bf8
            --to )
638bf8
                
638bf8
                # Redefine target flag.
638bf8
                FLAG_TO="$2"
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 2
638bf8
                ;;
2bd980
638bf8
            --quiet )
638bf8
                
638bf8
                # Redefine target flag.
638bf8
                FLAG_QUIET='true'
2bd980
638bf8
                # Rotate positional parameters.
638bf8
                shift 1
638bf8
                ;;
2bd980
638bf8
            --yes )
638bf8
                
638bf8
                # Redefine target flag.
638bf8
                FLAG_YES='true'
638bf8
638bf8
                # Rotate positional parameters.
638bf8
                shift 1
2bd980
                ;;
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
2bd980
    # Define directory used to store chapter's documentation entries.
2bd980
    # At this point, we need to take a desition about
2bd980
    # documentation-design, in order to answer the question: How do we
2bd980
    # assign chapters, sections and subsections automatically, based
2bd980
    # on the repository structure? 
2bd980
    #
2bd980
    # One solution would be: to use three chapters only to represent
2bd980
    # the repository's first level structure (i.e., trunk,
2bd980
    # branches, and tags) and handle everything else as sections. Sub
2bd980
    # and subsub section will not have their own files, they will be
2bd980
    # written inside section files instead.
2bd980
    ENTRYCHAPTER=$(echo $ENTRY | cut -d / -f-10)
2bd980
2bd980
    # Define chapter name for this documentation entry.
235556
    CHAPTERNAME=$(basename "$ENTRYCHAPTER")
2bd980
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
4c79b5
}