Blame Scripts/Functions/Help/help_getOptions.sh

4c79b5
#!/bin/bash
4c79b5
#
3a08eb
# help_getOptions.sh -- This function interpretes arguments passed to
3a08eb
# `manual' functionality and calls actions accordingly.
4c79b5
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# 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
3a08eb
function help_getOptions {
4c79b5
2bd980
    # Define short options we want to support.
2bd980
    local ARGSS=""
2bd980
2bd980
    # Define long options we want to support.
deaa54
    local ARGSL="quiet,answer-yes,dont-commit-changes,read,search:,edit,update,copy,delete,rename,format:"
2bd980
2bd980
    # Parse arguments using getopt(1) command parser.
793c4c
    cli_parseArguments
2bd980
2bd980
    # Reset positional parameters using output from (getopt) argument
2bd980
    # parser.
2bd980
    eval set -- "$ARGUMENTS"
2bd980
53c4b2
    # Define default action for help functionality.  This is, the
53c4b2
    # action performed when no non-option argument is passed to
53c4b2
    # `centos-art.sh' script command-line internface.
53c4b2
    if [[ $# -le 1 ]];then
53c4b2
        /usr/bin/info --node="Top" --file=${MANUAL_BASEFILE}.info.bz2
53c4b2
        exit
53c4b2
    fi
53c4b2
2bd980
    # Define action to take for each option passed.
2bd980
    while true; do
2bd980
        case "$1" in
2bd980
c145a8
            --quiet )
c145a8
                FLAG_QUIET="true"
c145a8
                FLAG_DONT_COMMIT_CHANGES="true"
c145a8
                shift 1
c145a8
                ;;
c145a8
3ccb0a
            --answer-yes )
3ccb0a
                FLAG_ANSWER="true"
3ccb0a
                shift 1
c145a8
                ;;
c145a8
c145a8
            --dont-commit-changes )
c145a8
                FLAG_DONT_COMMIT_CHANGES="true"
c145a8
                shift 1
c145a8
                ;;
c145a8
638bf8
            --search )
deaa54
                ACTIONNAM="searchIndex"
53c4b2
                FLAG_SEARCH="$2"
53c4b2
                shift 2
2bd980
                ;;
4c79b5
    
2bd980
            --edit )
deaa54
                ACTIONNAM="editEntry"
c145a8
                shift 1
2bd980
                ;;
1527e4
1527e4
            --copy )
deaa54
                ACTIONNAM="copyEntry"
1527e4
                shift 1
1527e4
                ;;
1527e4
    
1527e4
            --delete )
deaa54
                ACTIONNAM="deleteEntry"
1527e4
                shift 1
1527e4
                ;;
1527e4
1527e4
            --rename )
deaa54
                ACTIONNAM="renameEntry"
1527e4
                shift 1
1527e4
                ;;
4c79b5
    
638bf8
            --update )
deaa54
                ACTIONNAM="updateOutputFiles"
c145a8
                shift 1
2bd980
                ;;
4c79b5
    
961d96
            --read )
deaa54
                ACTIONNAM="searchNode"
bbb90e
                FLAG_DONT_COMMIT_CHANGES='true'
961d96
                shift 1
961d96
                ;;
deaa54
            
deaa54
            --format )
deaa54
                FLAG_FORMAT="$(cli_getRepoName $2 -f)"
deaa54
                if [[ ! $FLAG_FORMAT =~ '^(docbook|texinfo)$' ]];then
deaa54
                    cli_printMessage "`gettext "The format provided is not supported."`" --as-error-line
deaa54
                fi
deaa54
                shift 2
deaa54
                ;;
961d96
961d96
            -- )
961d96
                # Remove the `--' argument from the list of arguments
961d96
                # in order for processing non-option arguments
961d96
                # correctly. At this point all option arguments have
961d96
                # been processed already but the `--' argument still
961d96
                # remains to mark ending of option arguments and
961d96
                # begining of non-option arguments. The `--' argument
961d96
                # needs to be removed here in order to avoid
961d96
                # centos-art.sh script to process it as a path inside
961d96
                # the repository, which obviously is not.
961d96
                shift 1
2bd980
                break
bbb90e
                ;;
2bd980
        esac
2bd980
    done
2bd980
deaa54
    # Redefine function name to include the flag format in it.
deaa54
    FUNCNAM="${FUNCNAM}_${FLAG_FORMAT}"
deaa54
deaa54
    # Redefine action name using function name.
deaa54
    ACTIONNAM="${FUNCNAM}_${ACTIONNAM}"
deaa54
c145a8
    # Redefine ARGUMENTS variable using current positional parameters. 
793c4c
    cli_parseArgumentsReDef "$@"
b88dec
4c79b5
}