Blame Scripts/Bash/Functions/cli.sh

4c79b5
#!/bin/bash
4c79b5
#
c5b9d2
# cli.sh -- This function initiates centos-art command-line interface.
c5b9d2
# Variables defined in this function are accesible by all other
c5b9d2
# functions. The cli function is the first script executed by
4c79b5
# centos-art command-line onces invoked.
4c79b5
#
7cd8e9
# Copyright (C) 2009, 2010 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 cli {
4c79b5
cdebd1
    # Initialize global variables.
f19466
    local FUNCNAM=''
c5b9d2
    local FUNCDIR=''
c5b9d2
    local FUNCDIRNAM=''
c5b9d2
    local FUNCSCRIPT=''
c5b9d2
    local FUNCCONFIG=''
f19466
    local ACTIONNAM=''
f19466
    local ACTIONVAL=''
cdebd1
    local REGEX=''
f19466
    local ARGUMENTS=''
f19466
f19466
    # Redefine positional parameters stored inside ARGUMENTS variable.
f19466
    cli_doParseArgumentsReDef "$@"
f19466
c5b9d2
    # Define function directory (FUNCDIR). The directory path where
c5b9d2
    # functionalities are stored inside the repository.
c5b9d2
    FUNCDIR=/home/centos/artwork/trunk/Scripts/Bash/Functions
c5b9d2
c5b9d2
    # Define function name (FUNCNAM) variable from first command-line
c5b9d2
    # argument.  As convenction we use the first argument to determine
c5b9d2
    # the exact name of functionality to call.
c5b9d2
    FUNCNAM=$(cli_getRepoName "$1" 'f')
c5b9d2
    if [[ "$FUNCNAM" =~ '^[a-z]+$' ]];then
c5b9d2
c5b9d2
        # Define function directory. 
c5b9d2
        FUNCDIRNAM=$(cli_getRepoName $FUNCNAM 'd')
c5b9d2
c5b9d2
        # Define function file name.
c5b9d2
        FUNCSCRIPT=${FUNCDIR}/${FUNCDIRNAM}/${FUNCNAM}.sh
c5b9d2
c5b9d2
        # Define function configuration directory. The function
c5b9d2
        # configuration directory is used to store functionality's
c5b9d2
        # related files.
c5b9d2
        FUNCCONFIG=${FUNCDIR}/${FUNCDIRNAM}/Config
c5b9d2
c5b9d2
        # Check function script existence.
c5b9d2
        cli_checkFiles $FUNCSCRIPT 'f'
c5b9d2
c5b9d2
    else
c5b9d2
        # Print an error message and stop script execution.
c5b9d2
        cli_printMessage "`eval_gettext "The function \\\`\\\$FUNCNAM' is not valid."`" 'AsErrorLine'
c5b9d2
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
c5b9d2
    fi
c5b9d2
c5b9d2
    # Remove the first argument passed to centos-art.sh command-line
c5b9d2
    # in order to build optional arguments inside functionalities. We
c5b9d2
    # start counting from second argument (inclusive) on.
c5b9d2
    shift 1
c5b9d2
c5b9d2
    # Redefine positional parameters stored inside ARGUMENTS variable.
c5b9d2
    cli_doParseArgumentsReDef "$@"
b76c02
b76c02
    # Define default text editors used by centos-art.sh script.
4386e8
    if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then
4c79b5
        EDITOR='/usr/bin/vim'
4c79b5
    fi
b76c02
    
b76c02
    # Check text editor execution rights. 
b76c02
    cli_checkFiles $EDITOR 'x'
4c79b5
f19466
    # Initialize regular expression (REGEX) used to reduce file
f19466
    # processing. If no regular expression is defined, set regular
f19466
    # expression to match everything.
f19466
    REGEX='.+'
f19466
79b380
    # Go for function initialization. Keep the cli_getFunctions
79b380
    # function calling after all variables and arguments definitions.
79b380
    cli_getFunctions
4c79b5
4c79b5
}