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
#
ff1143
# 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 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=''
f19466
    local ARGUMENTS=''
f19466
558b58
    # Initialize default value to verbosity flag. The verbosity flag
476434
    # (--quiet) controls whether centos-art.sh script prints messages
ff1143
    # or not.
ff1143
    local FLAG_QUIET='false'
ff1143
    
558b58
    # Initialize default value to answer flag. The answer flag (--yes)
476434
    # controls whether centos-art.sh script does or does not pass
ff1143
    # confirmation request points.
ff1143
    local FLAG_YES='false'
ff1143
558b58
    # Initialize default value to filter flag. The filter flag
558b58
    # (--filter) is used mainly to reduce the number of files to
558b58
    # process. The value of this variable is interpreted as
558b58
    # egrep-posix regular expression.  As initial value, we use a
558b58
    # regular expression that matches everything.
558b58
    local FLAG_FILTER='.+'
558b58
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
861bb0
    # Define function directory. 
861bb0
    FUNCDIRNAM=$(cli_getRepoName "$FUNCNAM" 'd')
c5b9d2
861bb0
    # Define function file name.
861bb0
    FUNCSCRIPT=${FUNCDIR}/${FUNCDIRNAM}/${FUNCNAM}.sh
c5b9d2
861bb0
    # Check function script existence.
861bb0
    cli_checkFiles $FUNCSCRIPT 'f'
c5b9d2
861bb0
    # Define function configuration directory. The function
861bb0
    # configuration directory is used to store functionality's
861bb0
    # related files.
861bb0
    FUNCCONFIG=${FUNCDIR}/${FUNCDIRNAM}/Config
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
de5588
    # Parse positional parameters to retrive the value of common
de5588
    # arguments (e.g., --answer-yes, --filter, --quiet, etc.).
de5588
    cli_doParseArgumentsCommon
de5588
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
79b380
    # Go for function initialization. Keep the cli_getFunctions
79b380
    # function calling after all variables and arguments definitions.
79b380
    cli_getFunctions
4c79b5
4c79b5
}