From a129e42676352161c5a5c6b643f258dac24bf5b6 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Dec 28 2010 22:30:44 +0000 Subject: Update cli_getRepoTLDir.sh to retrive repository top level directory as both relative and absolute paths. --- diff --git a/Scripts/Bash/Functions/cli_getRepoTLDir.sh b/Scripts/Bash/Functions/cli_getRepoTLDir.sh index 2ffdb08..da1b338 100755 --- a/Scripts/Bash/Functions/cli_getRepoTLDir.sh +++ b/Scripts/Bash/Functions/cli_getRepoTLDir.sh @@ -3,8 +3,7 @@ # cli_getRepoTLDir.sh -- This function returns the repository top # level absolute path. The repository top level absolute path may be # /home/centos/artwork/trunk, /home/centos/artwork/branches, or -# /home/centos/artwork/tags. This function uses action value to -# determine which is the top level absolute path being used. +# /home/centos/artwork/tags. # # Copyright (C) 2009, 2010 Alain Reguera Delgado # @@ -29,7 +28,37 @@ function cli_getRepoTLDir { - echo $ACTIONVAL | sed -r \ - -e 's!^(/home/centos/artwork/(trunk|branches|tags)).+$!\1!') + local PATTERN='' + local REPLACE='' + local LOCATION='' + + # Define location. If first argument is provided use it as default + # location. Otherwise, if first argument is not provided, + # location takes the action value (ACTIONVAL) as default. + if [[ "$1" != '' ]];then + LOCATION="$1" + else + LOCATION="$ACTIONVAL" + fi + + # Verify location. + if [[ $LOCATION =~ '^/home/centos/artwork/(trunk|branches|tags)/.+$' ]];then + case "$2" in + -r|--relative ) + PATTERN='^/home/centos/artwork/(trunk|branches|tags)/.+$' + REPLACE='\1' + ;; + -a|--absolute|* ) + PATTERN='^(/home/centos/artwork/(trunk|branches|tags))/.+$' + REPLACE='\1' + ;; + esac + else + cli_printMessage "cli_getRepoTLDir: `eval_gettext "The location \\\`\\\$LOCATION' is not valid."`" 'AsErrorLine' + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Print location. + echo $LOCATION | sed -r "s!${PATTERN}!${REPLACE}!g" }