Blame Scripts/Bash/Functions/Locale/locale_getActions.sh

4c79b5
#!/bin/bash
4c79b5
#
6c8ab9
# locale_getActions.sh -- This function interprets arguments passed to
6c8ab9
# `locale' 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
4c79b5
function locale_getActions {
4c79b5
6c8ab9
    # Define short options we want to support.
786ebb
    local ARGSS=""
4c79b5
6c8ab9
    # Define long options we want to support.
bf6bff
    local ARGSL="update:,edit:,dont-create-mo"
4c79b5
6c8ab9
    # Parse arguments using getopt(1) command parser.
6c8ab9
    cli_doParseArguments
4c79b5
6c8ab9
    # Reset positional parameters using output from (getopt) argument
6c8ab9
    # parser.
6c8ab9
    eval set -- "$ARGUMENTS"
4c79b5
bf6bff
    # Look for options passed through command-line.
6c8ab9
    while true; do
6c8ab9
        case "$1" in
6c8ab9
786ebb
            --update )
6c8ab9
6c8ab9
                # Redefine action name.
4e4b4d
                ACTIONNAM="${FUNCNAM}_updateMessages"
6c8ab9
786ebb
                # Redefine action value.
786ebb
                ACTIONVAL="$2"
6c8ab9
bf6bff
                # Rotate positional parameters
786ebb
                shift 2
6c8ab9
                ;;
6c8ab9
6c8ab9
            --edit )
6c8ab9
6c8ab9
                # Redefine action name.
4e4b4d
                ACTIONNAM="${FUNCNAM}_editMessages"
786ebb
786ebb
                # Redefine action value.
786ebb
                ACTIONVAL="$2"
786ebb
bf6bff
                # Rotate positional parameters
786ebb
                shift 2
6c8ab9
                ;;
6c8ab9
0d4faa
            --dont-create-mo )
6a8fb5
6a8fb5
                # Redefine create machine object flag.
0d4faa
                FLAG_DONT_CREATE_MO="true"
6a8fb5
bf6bff
                # Rotate positional parameters
6a8fb5
                shift 1
6a8fb5
                ;;
6a8fb5
6c8ab9
            * )
6c8ab9
                break
4e4b4d
                ;;
6c8ab9
        esac
6c8ab9
    done
6c8ab9
786ebb
    # Check action value. Be sure the action value matches the
786ebb
    # convenctions defined for source locations inside the working
786ebb
    # copy.
786ebb
    cli_checkRepoDirSource
786ebb
bf6bff
    # Define locales base directory where locale directory structures
bf6bff
    # are stored in.
bf6bff
    local BASEDIR="$(cli_getRepoTLDir)/Locales"
bf6bff
bf6bff
    # Define locales work directory. This is the place where locale
bf6bff
    # files (e.g., .po, .pot, .mo), for a specific parent directories,
bf6bff
    # are stored in. There is one locale work directory for each
bf6bff
    # parent directory or said differently, each parent directory has
bf6bff
    # a parallel directory under `trunk/Locales' to store its
bf6bff
    # translation messages.
bf6bff
    local WORKDIR=$(echo $ACTIONVAL | sed -r \
740ed4
            -e 's!trunk/(Identity|Manuals|Scripts)!trunk/Locales/\1!') 
740ed4
  
bf6bff
    # Syncronize changes between the working copy and the central
f4a797
    # repository to bring down changes.
bf6bff
    cli_commitRepoChanges "${WORKDIR}"
bf6bff
6c8ab9
    # Execute action name.
6c8ab9
    if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then
6c8ab9
        eval $ACTIONNAM
6c8ab9
    else
6c8ab9
        cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine'
6c8ab9
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
6c8ab9
    fi
4c79b5
bf6bff
    # Syncronize changes between the working copy and the central
f4a797
    # repository to commit up changes.
bf6bff
    cli_commitRepoChanges "${WORKDIR}"
bf6bff
4c79b5
}