Blame Scripts/Modules/Hello/hello_getOptions.sh

Alain Reguera Delgado e051b3
#!/bin/bash
Alain Reguera Delgado e051b3
######################################################################
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
#   hello_getOptions.sh -- Interpret module-specific options for hello.
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
#   Written by:
Alain Reguera Delgado e051b3
#   * Alain Reguera Delgado <al@centos.org.cu>, 2013
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado e051b3
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado e051b3
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado e051b3
# your option) any later version.
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado e051b3
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado e051b3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado e051b3
# General Public License for more details.
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado e051b3
# along with this program; if not, write to the Free Software
Alain Reguera Delgado e051b3
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado e051b3
#
Alain Reguera Delgado e051b3
######################################################################
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
function hello_getOptions {
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Define short options we want to support.
Alain Reguera Delgado e051b3
    local ARGSS="h::,v,g:,l,u,c,r"
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Define long options we want to support.
Alain Reguera Delgado e051b3
    local ARGSL="help::,version,greeting:,lower,upper,camel,random"
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Redefine arguments using getopt(1) command parser.
Alain Reguera Delgado e051b3
    tcar_setModuleArguments
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Reset positional parameters on this function, using output
Alain Reguera Delgado e051b3
    # produced from (getopt) arguments parser.
Alain Reguera Delgado e051b3
    eval set -- "${TCAR_MODULE_ARGUMENT}"
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Look for options passed through command-line.
Alain Reguera Delgado e051b3
    while true; do
Alain Reguera Delgado e051b3
        case "${1}" in
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -h | --help )
Alain Reguera Delgado e051b3
                tcar_printHelp "${2}"
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -v | --version )
Alain Reguera Delgado e051b3
                tcar_printVersion "${TCAR_MODULE_NAME}"
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -g | --greeting )
Alain Reguera Delgado e051b3
                HELLO_WORLD="${2:-${HELLO_WORLD}}"
Alain Reguera Delgado e051b3
                shift 2
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -l | --lower )
Alain Reguera Delgado e051b3
                ACTIONS="lower ${ACTIONS}"
Alain Reguera Delgado e051b3
                shift 1
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -u | --upper )
Alain Reguera Delgado e051b3
                ACTIONS="upper ${ACTIONS}"
Alain Reguera Delgado e051b3
                shift 1
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -c | --camel )
Alain Reguera Delgado e051b3
                ACTIONS="camel ${ACTIONS}"
Alain Reguera Delgado e051b3
                shift 1
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -r | --random )
Alain Reguera Delgado e051b3
                ACTIONS="random ${ACTIONS}"
Alain Reguera Delgado e051b3
                shift 1
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
            -- )
Alain Reguera Delgado e051b3
                shift 1
Alain Reguera Delgado e051b3
                break
Alain Reguera Delgado e051b3
                ;;
Alain Reguera Delgado e051b3
        esac
Alain Reguera Delgado e051b3
    done
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
    # Redefine arguments using current positional parameters. Only
Alain Reguera Delgado e051b3
    # paths should remain as arguments, at this point.
Alain Reguera Delgado e051b3
    TCAR_MODULE_ARGUMENT="${@}"
Alain Reguera Delgado e051b3
Alain Reguera Delgado e051b3
}