Blame Scripts/Functions/cli_getRepoTLDir.sh

7a5604
#!/bin/bash
7a5604
#
f128ea
# cli_getRepoTLDir.sh -- This function returns the repository top
f128ea
# level absolute path. The repository top level absolute path may be
f128ea
# /home/centos/artwork/trunk, /home/centos/artwork/branches, or
a129e4
# /home/centos/artwork/tags.
7a5604
#
fcf4c2
# Copyright (C) 2009-2011 Alain Reguera Delgado
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
fa95b1
# the Free Software Foundation; either version 2 of the License, or
fa95b1
# (at your option) any later version.
fa95b1
#
7a5604
# This program is distributed in the hope that it will be useful, but
7a5604
# WITHOUT ANY WARRANTY; without even the implied warranty of
7a5604
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7a5604
# General Public License for more details.
7a5604
#
7a5604
# You should have received a copy of the GNU General Public License
7a5604
# along with this program; if not, write to the Free Software
7a5604
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
7a5604
# USA.
7a5604
# ----------------------------------------------------------------------
7a5604
# $Id$
7a5604
# ----------------------------------------------------------------------
7a5604
f128ea
function cli_getRepoTLDir {
7a5604
a129e4
    local PATTERN=''
a129e4
    local REPLACE=''
a129e4
    local LOCATION=''
a129e4
    
a129e4
    # Define location. If first argument is provided use it as default
a129e4
    # location.  Otherwise, if first argument is not provided,
a129e4
    # location takes the action value (ACTIONVAL) as default.
a129e4
    if [[ "$1" != '' ]];then
a129e4
        LOCATION="$1"
a129e4
    else
a129e4
        LOCATION="$ACTIONVAL"
a129e4
    fi
a129e4
a129e4
    # Verify location.
7b46a4
    if [[ $LOCATION =~ "^${HOME}/artwork/(trunk|branches|tags)/.+$" ]];then
a129e4
        case "$2" in
a129e4
            -r|--relative )
7b46a4
                PATTERN="^${HOME}/artwork/(trunk|branches|tags)/.+$"
a129e4
                REPLACE='\1'
a129e4
                ;;
a129e4
            -a|--absolute|* )
7b46a4
                PATTERN="^(${HOME}/artwork/(trunk|branches|tags))/.+$"
a129e4
                REPLACE='\1'
a129e4
                ;;
a129e4
        esac
a129e4
    else
9fa281
        cli_printMessage "${FUNCNAME}: `eval_gettext "The location \\\`\\\$LOCATION' is not valid."`" 'AsErrorLine'
eee226
        cli_printMessage "${FUNCDIRNAM}" 'AsToKnowMoreLine'
a129e4
    fi
a129e4
a129e4
    # Print location.
a129e4
    echo $LOCATION | sed -r "s!${PATTERN}!${REPLACE}!g"
7a5604
7a5604
}